Welcome to WebmasterWorld Guest from 54.226.213.110

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)

Preferred Member

10+ Year Member

joined:Jan 4, 2005
posts:621
votes: 0


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.

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

New User

5+ Year Member

joined:Apr 24, 2010
posts:23
votes: 0


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)

Senior Member

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

joined:Mar 30, 2003
posts:3719
votes: 0


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].

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

Preferred Member

10+ Year Member

joined:Jan 4, 2005
posts:621
votes: 0


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.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members