Reputation: 1222
When I use current_timestamp
with MySQL, I get the correct time, but when I use
$mysqldate = date( 'Y-m-d H:i:s' );
I get the date with with an hour delay (eg, 4:42 PM is 5:42 PM). I understood that both function use the server's local time - can someone explain the difference?
Thanks.
Upvotes: 8
Views: 4710
Reputation: 21660
There are php locale settings, it takes it from php.ini, not from system time
Upvotes: 2
Reputation: 7975
The global system time will be set via the /etc/localtime file, which will be either a symlink or a copy of a zone file from /usr/share/zoneinfo/ on most systems. Applications will use this as their default.
PHP can override this in a couple different ways:
putenv("TZ=US/Central");
MySQL can override this by running the following query immediately after connecting:
SET time_zone = 'US/Central'
Upvotes: 9
Reputation: 92752
Maybe your PHP server thinks it's in a different time zone or it uses different locale and daylight saving time rules.
Upvotes: 1