I would like to store the input of the calendar-field in my JTable::store.

To do so I'm doing this:


    <field name="creationdate"
           format="%d.%m.%Y %H:%M"

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();
        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());

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:



    var_dump(JFactory::getDate($input[ 'creationdate' ])->toSql());


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.

1 Answer 1


I looked at the code for this. JDate::dateformat is public, which means ANY code can modify the value. I would start doing a grep/search through my source tree (and any plugins/modules/libraries) to look for assignments to it.

Looking at the Time difference issue, what I think is that JFactory() is constructing the date two different ways. The first, with the value of $input['creationdate'] is passing in a character string. The second is passing a numeric value. If you look at the constructor for JDate(), if the date argument is a numeric, it converts the timestamp to UTC.

What you should also do is dump the value for date->getTimezone() to examine them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.