homepage Welcome to WebmasterWorld Guest from 54.167.185.110
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved