I would like to store the input of the calendar-field in my JTable::store.
To do so I'm doing this:
Form-declaration:
<field name="creationdate"
type="calendar"
default="NOW"
label="COM_BESTIA_FIELDS_CREDITCREATIONDATE_LABEL"
description="COM_BESTIA_FIELDS_CREDITCREATIONDATE_DESC"
format="%d.%m.%Y %H:%M"
filter="user_utc"/>
Store-Method in JTable:
if ( !empty( $input[ 'creationdate' ] ) && !( $input[ 'creationdate' ] == "0000-00-00 00:00:00" ) ) // Prepare date to be saved in database
{
// Set this to a format the sql-table is able to save
$date = JFactory::getDate($input[ 'creationdate' ]);
$this->creationdate = $date->toSql();
}
else
{
throw new Exception(JText::_('COM_BESTIA_ERROR_INCORRECTDATES'));
}
This works fine. If I var_dump the output doing
var_dump(JFactory::getDate($input[ 'creationdate' ])->toSql());
var_dump(JFactory::getDate($this->creationdate)->toSql());
I'm getting this result:
string(19) "2016-05-13 09:30:00" string(19) "2016-05-13 09:30:00"
This is correct.
But in another form I'm getting this result for:
XML:
var_dump:
var_dump(JFactory::getDate($input[ 'creationdate' ])->toSql());
var_dump(JFactory::getDate($this->creationdate)->toSql());
Result:
string(16) "13.05.2016 09:41" string(19) "2016-05-13 07:41:00"
Any idea why I'm getting different values?
Edit: The reason why I'm using the input sometimes instead of $this->creationdate
is that I'm using a CLI script to create elements. And until now I was not able to get the values to database if I use $this->creationdate
and not the input.