I have records that user's create by submitting a form on my website. When they create a record, a timestamp is also created by default to explain when the record was created. From what I'm aware they are all in UTC/GMT Time which is 4 hours off my EST timezone. When I loop through the records to echo them into a table, I'd like for the timestamp's to show the time of the user logged in. Is there easy way of going about this by changing the variable of the timestamp?
In PHP:
date('Y-m-d H:i:s',strtotime('-4 hours',strtotime(TIME_FROM_DB)));
For more about date() & strtotime() see http://php.net/manual/de/
In MYSQL:
SELECT DATE_ADD(time_field, INTERVAL 31 DAY);
or
SELECT CONVERT_TZ('2004-01-01 12:00:00','GMT','MET');
http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html#function_adddate
hope helps
Using date_default_timezone_set('US/Eastern');
in PHP will convert the time-zone of your code to that timezone.
When you query the database with NOW()
in the SQL-query (or use $currentTime = date('Y-m-d H:i:s', time());
in PHP, and insert $currentTime
), it'll insert the time of the time-zone defined above.