Mysql is not converting timestamp to the timezone of PHP query

I have a mysql database in this format

And I am trying to fetch the values through a php document and convert them into json on the timezone of the user (or maybe just GMT-6 would suffice) but the json outputs from the php document are as follows:

[{"timestamp":"2018-06-13 19:52:05","temperature":"79.83","humidity":"41.89","pressure":"99.35"},{"timestamp":"2018-06...

Still in UTC time, I have tried adding

date_default_timezone_set('America/Los_Angeles');

To the php document, but the time never changes, how would I solve this?

phpmysqlsqldatetimetimestamp-with-timezone

Answers

answered 4 months ago sticky bit #1

Use convert_tz() on the timestamps in your query to convert them from one timezone to another, e.g.:

... convert_tz(`timestamp`, 'Etc/UTC', 'America/Los_Angeles') ...

Make sure to follow the procedure "Populating the Time Zone Tables" as described in "5.1.12 MySQL Server Time Zone Support" to have the time zones available or to check which are available in your system.

comments powered by Disqus