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

Skip to first unread message

Nico van de Kamp

Jun 21, 2021, 4:48:19 PMJun 21
to Joomla! General Development

I'm looking at the com_content (article) how the created time is saved to the database.
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
0 new messages