2

Working with php and mysql. In test.php file have this simple script:

echo date('Y m d h:i');    
echo date_default_timezone_get();
DB::execute('insert into test (date) values (now()) ');

In the browser it displays GMT as a result of server date_default_timezone_get function and date like "2015 07 16 20:06". However in the DB the value is stored with 2 hours added to the date like it was in central europe time (2015 07 16 22:06). I've checked the mysql variable TIME_ZONE is set to SYSTEM, so I think that the date stored in the DB should be the same as it is displayed from php server? I'm in central europe in the moment, is it possible that mysql knows this somehow and sets the date based on my computer system timezone?

when I run this i mysql

select @@time_zone, now(), utc_timestamp()

i receive: SYSTEM | 2015-07-16 22:27:22 | 2015-07-16 20:27:22 Also I've see that other mysql variable SYSTEM_TIME_ZONE is set to CEST. maybe that's why i have date stored in central europe timezone? Even if in php i have different time zone and mysql TIME_ZONE is set to system? Date field in the table is datetime format

abiku
  • 2,236
  • 3
  • 25
  • 30
  • 1
    There are multiple solutions based on your privileges. This will help you out: https://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html – Crackertastic Jul 16 '15 at 20:21
  • Please edit your question and tell us what you get when you issue this command. `select @@time_zone, now(), utc_timestamp()` Also, please tell us the datatype of your `date` column in your `test` table, This matters. (Extra credit question: why does the datatype of the column matter?) – O. Jones Jul 16 '15 at 20:24

0 Answers0