Reputation: 4945
I have a sql script running on a linux from a php file that always returns the time as 2 hours ahead of us. The linux box runs here locally and when I do a "date" in the shell it returns the correct time. Any ideas why I a being returned CURTIME 2 hours ahead?
Even though I run
echo date('Y-m-d H:i:s');
echo date('Y-m-d H:i:s', mktime());
echo exec('date');
all echo the correct time which for me right now is
2013-08-27 12:44:52
2013-08-27 12:44:52
Tue Aug 27 12:44:52 PDT 2013
but no matter what I do it inserts into mysql db at 14:44:52
Upvotes: 0
Views: 273
Reputation: 36311
From Mysql:
The value is expressed in the current time zone.
If you want it to display in your timezone, you need to convert it to the timzeone you want to do something like this Documentation:
select convert_tz(now(), @@global.time_zone, '-5:00');
select date(convert_tz(now(), @@global.time_zone, '-5:00'));
select time(convert_tz(now(), @@global.time_zone, '-5:00'));
# The second value gets the time of the server so it knows what to convert from.
# The third value is your timezone you want to display
# It can either be an offset, or name (if table is installed):
# 'UTC', 'PST', 'MET', and so on
Upvotes: 1