Grant Holmes Posted February 7, 2008 Share Posted February 7, 2008 I have a processing form reporting the time when a record is inserted. This field is never changed. However, our server (Yahoo) is in London. My client is in CA. I'd like to post a time relevant to LA. In my page I do: $time=date("Y-m-d H:i:s"); Is there a way to subtract the 9 hour difference? H-9?? Quote Link to comment https://forums.phpfreaks.com/topic/89941-solved-server-time-adjustment/ Share on other sites More sharing options...
phpSensei Posted February 7, 2008 Share Posted February 7, 2008 Timezone --- --- e Timezone identifier (added in PHP 5.1.0) Examples: UTC, GMT, Atlantic/Azores I (capital i) Whether or not the date is in daylight saving time 1 if Daylight Saving Time, 0 otherwise. O Difference to Greenwich time (GMT) in hours Example: +0200 P Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3) Example: +02:00 T Timezone abbreviation Examples: EST, MDT ... Z Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. -43200 through 50400 http://ca3.php.net/manual/en/function.date.php Try that Quote Link to comment https://forums.phpfreaks.com/topic/89941-solved-server-time-adjustment/#findComment-461092 Share on other sites More sharing options...
rhodesa Posted February 7, 2008 Share Posted February 7, 2008 If you want the date() function to return dates/times in CA timezone, use this at the beginning of your script: date_ default_ timezone_ set('America/Los_Angeles'); As far as making a script show dates auto-adjusted to the client's timezone, it's a little trickier. The only way to get the client's timezone is with javascript. Quote Link to comment https://forums.phpfreaks.com/topic/89941-solved-server-time-adjustment/#findComment-461099 Share on other sites More sharing options...
Grant Holmes Posted February 7, 2008 Author Share Posted February 7, 2008 Thanks for the help gang. phpSensei, I read that page, but I'm noob to PHP and have no idea what to edit/add/whatever. rhodesa, (see above on being a newbie)... I put that above my code within the php like this: date_ default_ timezone_ set('America/Los_Angeles'); $time=date("Y-m-d H:i:s"); but then the page failed to display. HELP!? Quote Link to comment https://forums.phpfreaks.com/topic/89941-solved-server-time-adjustment/#findComment-461104 Share on other sites More sharing options...
rhodesa Posted February 7, 2008 Share Posted February 7, 2008 sorry...i copied/pasted the function name and it ended up with spaces in there: date_default_timezone_set('America/Los_Angeles'); $time=date("Y-m-d H:i:s T"); I also added a T to your date format so you could see what timezone it was using Quote Link to comment https://forums.phpfreaks.com/topic/89941-solved-server-time-adjustment/#findComment-461112 Share on other sites More sharing options...
Grant Holmes Posted February 7, 2008 Author Share Posted February 7, 2008 rhodesa, I need to leave the T off, as I store this value in my table and the field isn't set for that, so would leaving it off still work? Quote Link to comment https://forums.phpfreaks.com/topic/89941-solved-server-time-adjustment/#findComment-461126 Share on other sites More sharing options...
rhodesa Posted February 7, 2008 Share Posted February 7, 2008 of course...i just added it in for debug purposes...so you could confirm which TZ it was using Quote Link to comment https://forums.phpfreaks.com/topic/89941-solved-server-time-adjustment/#findComment-461154 Share on other sites More sharing options...
phpSensei Posted February 7, 2008 Share Posted February 7, 2008 <?php $timezone = "America/Los_Angeles"; putenv('TZ=$timezone'); echo date('M j Y, H:m:s'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/89941-solved-server-time-adjustment/#findComment-461160 Share on other sites More sharing options...
Grant Holmes Posted February 7, 2008 Author Share Posted February 7, 2008 phpSensei, your solution returns zeros: "0000-00-00 00:00:00" and I don't see where you're assigning the value to: $time rhodesa, yours still returns a blank page. Quote Link to comment https://forums.phpfreaks.com/topic/89941-solved-server-time-adjustment/#findComment-461193 Share on other sites More sharing options...
phpSensei Posted February 7, 2008 Share Posted February 7, 2008 phpSensei, your solution returns zeros: "0000-00-00 00:00:00" and I don't see where you're assigning the value to: $time rhodesa, yours still returns a blank page. putenv('TZ=$timezone'); try <?php $timezone = "America/Los_Angeles"; putenv('TZ=$timezone'); echo date('Y-m-d h:i:s'); ?> returns: 2008-02-07 03:31:12 Quote Link to comment https://forums.phpfreaks.com/topic/89941-solved-server-time-adjustment/#findComment-461199 Share on other sites More sharing options...
rhodesa Posted February 7, 2008 Share Posted February 7, 2008 I assume on mine, you put in an echo? <?php date_default_timezone_set('America/Los_Angeles'); $time=date("Y-m-d H:i:s"); echo "In CA it is currently ".$time; ?> Quote Link to comment https://forums.phpfreaks.com/topic/89941-solved-server-time-adjustment/#findComment-461204 Share on other sites More sharing options...
phpSensei Posted February 7, 2008 Share Posted February 7, 2008 <?php putenv('TZ=America/Los_Angeles'); echo date('Y-m-d h:i:s'); ?> Okay this works: 2008-02-07 12:31:56 Quote Link to comment https://forums.phpfreaks.com/topic/89941-solved-server-time-adjustment/#findComment-461206 Share on other sites More sharing options...
rhodesa Posted February 7, 2008 Share Posted February 7, 2008 Overshadowed by the almighty phpSensei..... :'( Quote Link to comment https://forums.phpfreaks.com/topic/89941-solved-server-time-adjustment/#findComment-461212 Share on other sites More sharing options...
phpSensei Posted February 7, 2008 Share Posted February 7, 2008 Overshadowed by the almighty phpSensei..... :'( Your Great Almighty Sensei... lol Quote Link to comment https://forums.phpfreaks.com/topic/89941-solved-server-time-adjustment/#findComment-461217 Share on other sites More sharing options...
Grant Holmes Posted February 7, 2008 Author Share Posted February 7, 2008 Okay kids, it's getting deep. Yes, that worked. I'm not sure why. I'm SURE I don't care!! Thanks a BUNCH!!!! hey, if you're bored... I'm stuck on this one: More Header Fun Quote Link to comment https://forums.phpfreaks.com/topic/89941-solved-server-time-adjustment/#findComment-461223 Share on other sites More sharing options...
phpSensei Posted February 7, 2008 Share Posted February 7, 2008 Okay kids, it's getting deep. Yes, that worked. I'm not sure why. I'm SURE I don't care!! Thanks a BUNCH!!!! hey, if you're bored... I'm stuck on this one: More Header Fun Not sure why it worked? lol what do you mean? I can explain the code if you want... Quote Link to comment https://forums.phpfreaks.com/topic/89941-solved-server-time-adjustment/#findComment-461224 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.