Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

php timezones and mysql inserts into db



3:59 pm on Aug 16, 2010 (gmt 0)

10+ Year Member

Hi there,

I have a client in one timezone, GMT or UTC + 2.

The server is in GMT/UTC -5

The db table columns are datetime.

How can I insert into the db, the datetime in the users time?

I've looked at a couple of things and either a) they don't work or b) I don't understand fully what is going on.

Any help would be great.



11:59 pm on Aug 16, 2010 (gmt 0)

5+ Year Member

If you are using the time() function to return a Unix timestamp, you can take away or add the amount of seconds. 3600 is 1 hour. In your case, there is a 7 hour difference in front of the server time, so you want:

$timestamp = time();
$timedifference = 25200; // 3600 multiplied by amount of hours
$newtimestamp = $timestamp + $timedifference;

echo $newtimestamp . '<br />';
date ('d-m-Y,h:i:s',$newtimestamp);


6:10 am on Aug 17, 2010 (gmt 0)

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member

If you are using PHP5, use date_default_timezone_set [php.net] to set the correct timezone for your clients, based on their location. All date and time functions will automatically be correct.

If not, try strtotime [php.net].



7:35 am on Aug 17, 2010 (gmt 0)

10+ Year Member

Thanks, I used a combination of both to sort it out. Was a bit repetitive and boring but easy enough and a good solution.

Thanks for the help.

Featured Threads

Hot Threads This Week

Hot Threads This Month