How to save the date in the database, with taking into account the timezone?

6 views
Skip to first unread message

Nico van de Kamp

unread,
Jun 21, 2021, 4:48:19 PM6/21/21
to Joomla! General Development

Hello,
I'm looking at the com_content (article) how the created time is saved to the database.
example:
the real time is:                      2021-06-17 19:48:56
time saved in database:       2021-06-17 17:48:56
time presented detail page: 2021-06-17 19:48:56

So that's correct.
The first save is working good with: $this->created_time = $date->toSql();, the value's are as the date value's saved for an article.

But after every update it goes wrong. After every update save two hours are added. This is due that the presented time, as here:  2021-06-17 19:48:56, is send to the save function and not corrected with UTC time. The value '2021-06-17 19:48:56' is saved in the database and now  '2021-06-17 21:48:56.

I was expected that this should be corrected by the Joomla framework.
I have looked at how-to-use-JDate, but there is not an good code example.

I have been debugging saving of an article, but can't find clearly find what is needed to correct the time with USER_UTC.

Does somebody have an idea how to do this, or know an code example how this can be solved?
Reply all
Reply to author
Forward
0 new messages