I'm trying to insert some data into the database where the table has a column of date
which is of type timestamp
and a default value of CURRENT_TIMESTAMP
.
I've tried the following methods to change the timezone:
Inside the php-5.6.ini file, modified these lines:
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = America/Los_Angeles
Saved the file and called sudo service httpd restart
as well as sudo service mysql restart
. I'd also like to note i"m using an ec2 instance if that has any effect.
I'm using the slim framework, so I've tried calling date_default_timezone_set('America/Los_Angeles');
inside the index.php
file, still no change.
The clock is always an hour behind, whether I set the timezone to America or Asia.
Also tried ini_set('date.timezone', 'Asia/Singapore');
Tried calling SET time_zone = 'America/New_York'
inside mySql work bench but returns #1298 - Unknown or incorrect time zone:
. Therefore, inside terminal I called mysql_tzinfo_to_sql /usr/share/zoneinfo
which seems to do something, but doesn't actually change anything. Still the same issue
php.ini
settings do not change the timezone of your mysql server. It change the timezone for apache server only. To change the mysql timezone issue the command:
SET time_zone = 'America/New_York';
from mysql terminal. This will automatically change the date/time obtained from all the TIMESTAMP
fields.
If you want to do it from php, then instead of the default timestamp
value pass the value from php like:
$datetime = date('Y-m-d H:i:s');
and insert the value of $datetime
in timestamp
column.