How can I get the local server\'s timezone without relying on php.ini
or other configuration files?
I am looking for an output similar to the output of
You don't actually need to know what "timezone" MySQL is running on - you merely need to know the difference to UTC.
To get that you can simply ask MySQL:
SELECT TIMESTAMPDIFF(HOUR, UTC_TIMESTAMP, NOW())
Since the value of NOW()
is based on the timezone MySQL is running on, that will read the difference between NOW()
and the UTC time, in hours. You can then use that value to create a full timestamp like 2016-04-15T15:52:01+01:00
which can be used in DateTime::__construct()
.
You can then let PHP worry about the difference the timezones between the application and database servers by comparing DateTime
objects... and that should work on all systems.