Skip to content
Advertisement

Store in UTC in SQLite and display in local timezone with PHP

I have a table containing a datetime column:

and I add a row (storing the datetime of the addition of the row in UTC) with

This works. Now when displaying the rows:

the date is displayed like this, in UTC: 2019-04-27 16:41:33.

How to display it in the local timezone instead? (including Daylight Saving)

I can imagine there are different options:

  • store directly in SQLite with local timezone (but I think this is not good practice)

  • store in SQLite in UTC, and do the UTC->local timezone conversion during the SELECT. How?

  • store in SQLite in UTC, and do the UTC->local timezone conversion via PHP.

How to do this properly?

Advertisement

Answer

As suggested by a comment, this page mentions the localtime modifier. Here is a solution:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement