woolyg Posted August 2, 2007 Share Posted August 2, 2007 Hi all, I'm inputting a DATETIME timestamp of $now into my table <? $now = date("Y-m-d H:i:s"); ?> - which enters the exact time of update into the table. The problem is, is that I'm in Dublin (GMT) and the hosting server is in the US - 7 hours behind - so if I entered data at exactly midday in dublin, the value displayed is 5am. Can someone guide me as to how I can alter the variable [b]$now[/b] to show Dublin time? Any help appreciated, Woolyg Quote Link to comment https://forums.phpfreaks.com/topic/62963-server-time-8-hours/ Share on other sites More sharing options...
hitman6003 Posted August 2, 2007 Share Posted August 2, 2007 Use the setlocale function http://www.php.net/setlocale Quote Link to comment https://forums.phpfreaks.com/topic/62963-server-time-8-hours/#findComment-313517 Share on other sites More sharing options...
woolyg Posted August 2, 2007 Author Share Posted August 2, 2007 ..so if I use the setlocale function at the start of a page, my '$now' declaration will return Dublin time? Does the following work, or would I need to follow GB for GMT? <?php /* Set locale to Ireland */ setlocale(LC_ALL, 'ie_IE'); ?> Thanks, Woolyg Quote Link to comment https://forums.phpfreaks.com/topic/62963-server-time-8-hours/#findComment-313529 Share on other sites More sharing options...
hitman6003 Posted August 2, 2007 Share Posted August 2, 2007 I gave you the wrong function...I think this one would be better: date_default_timezone_set('Europe/Dublin'); http://www.php.net/date_default_timezone_set() Quote Link to comment https://forums.phpfreaks.com/topic/62963-server-time-8-hours/#findComment-313533 Share on other sites More sharing options...
woolyg Posted August 2, 2007 Author Share Posted August 2, 2007 Hmm - I placed this towards the start of the page but now the page isn't displaying. Quote Link to comment https://forums.phpfreaks.com/topic/62963-server-time-8-hours/#findComment-313549 Share on other sites More sharing options...
hitman6003 Posted August 2, 2007 Share Posted August 2, 2007 What version of php are you using? That will only work in php >= 5.1 This post may help... http://us3.php.net/manual/en/function.date-default-timezone-set.php#75648 Quote Link to comment https://forums.phpfreaks.com/topic/62963-server-time-8-hours/#findComment-313550 Share on other sites More sharing options...
woolyg Posted August 2, 2007 Author Share Posted August 2, 2007 Ah crud. The host's PHP version is 4.4.6. Any other way it can be done? Quote Link to comment https://forums.phpfreaks.com/topic/62963-server-time-8-hours/#findComment-313551 Share on other sites More sharing options...
lightningstrike Posted August 2, 2007 Share Posted August 2, 2007 umm perhaps this. $stamp = time() - (8*3600); $now = date("Y-m-d H:i:s",$stamp); Quote Link to comment https://forums.phpfreaks.com/topic/62963-server-time-8-hours/#findComment-313571 Share on other sites More sharing options...
woolyg Posted August 2, 2007 Author Share Posted August 2, 2007 Cheers all - I ended up using $now = date("Y-m-d H:i:s", strtotime('+7 hours')); Hope there's no underlying problems with using it in this manner... Woolyg Quote Link to comment https://forums.phpfreaks.com/topic/62963-server-time-8-hours/#findComment-313588 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.