Home » Php » PHP timezone/date() incorrect or PHP thinks it's a T.A.R.D.I.S

PHP timezone/date() incorrect or PHP thinks it's a T.A.R.D.I.S

Posted by: admin July 12, 2020 Leave a comment


I have my server synced to UTC, which is currently 2013-05-23 18:13:56 give or take.

When I run date("Y-m-d H:i:s"), I get 2013-05-24 07:13:56.

I checked the php.ini file, the timezone is set date.timezone = 'UTC', which I thought would change the timezone to reflect against what the system’s timezone setting is. So I turned it off (like this: ;date.timezone = 'UTC') and I still get an incorrect timestamp.

All this wibbly wobbly timey wimey stuff has got me more confused that a Dalek with a valentines day card.


How to&Answers:

UTC is a reference, not a time zone.

Every country/zones are refered to UTC.

You should use the time zone of the country you need to use the time.

For example:

date("Y-m-d H:i:s");

Note: Europe/London is UTC+1 (weird eu ? UTC is supposed to be greenwich that pass through London BUT UK uses time savings so the difference)

server time should be correct either, putting it to “UTC” does not mean either a good thing, if is more importante your server is at the “correct time” for the “correct timezone”

How to know which time zone is the server:
from console, type:

$ date

and the server responds with the time:

Thu May 23 13:22:23 CDT 2013

Note the CDT, it’s the time zone. Which time zone uses your server ?


What I have found is that my T.A.R.D.I.S. will set itself to the local time, so wherever it finds itself, that is where my SQL will set itself. Therefore, I always make sure my Ubuntu uses the correct time zone. It’s the system time, not just SQL time. Less wibbly wobbly that way.


I’m guessing you’re using PHP < 5.4

date.timezone string

The default timezone used by all date/time functions. Prior to PHP 5.4.0, this would only work if the TZ environment variable was not set. The precedence order for which timezone is used if none is
explicitly mentioned is described in the date_default_timezone_get()
page. See List of Supported Timezones for a list of supported