Welcome to WebmasterWorld Guest from 126.96.36.199 , register , free tools , login , search , subscribe , help , library , announcements , recent posts , open posts Subscribe and Support WebmasterWorld
php timezones and mysql inserts into db Pico_Train msg:4187785 3:59 pm on Aug 16, 2010 (gmt 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!
Sp4rkyM4rk msg:4188016 11:59 pm on Aug 16, 2010 (gmt 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); dreamcatcher msg:4188116 6:10 am on Aug 17, 2010 (gmt 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
Pico_Train msg:4188137 7:35 am on Aug 17, 2010 (gmt 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.