Forum Moderators: coopster

Message Too Old, No Replies

Problems getting the day in PHP

         

Elric99

8:30 am on Jun 3, 2010 (gmt 0)

10+ Year Member



My server is in the US so the time is offset by -5 hours. I need to work out what day it is in the UK, but this is not accurate with the -5 hours.

Could someone please show me how to get the current day, in the UK. I've been googling for about an hour and can't seem to solve this simple problem.

Matthew1980

8:48 am on Jun 3, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Elric99

date("Y-d-m", strtotime("- 5 hours"));//not recommeneded, as this will distort the time for everyone, unless you assign the offset to a cookie and set it dynamically ;p

Or you can set the timezone, check out php.net for time_zone
[php.net ]
[uk2.php.net ]

You get the idea there..

Cheers,
MRb

Elric99

9:08 am on Jun 3, 2010 (gmt 0)

10+ Year Member



Hi, thanks for the reply.

I think I may have also found another way to do it:

<?php

print gmdate("Y-m-d\TH:i:s\Z");

?>

I think gmdate converts to GMT.

Matthew1980

10:15 am on Jun 3, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Elric99,

Off php.net

Identical to the date() function except that the time returned is Greenwich Mean Time (GMT).


Nifty, not used this one before, give the current time as the 2nd parameter, and it converts it to GMT - going from the desired format stated by the first parameter.

Nice find ;)

Cheers,
MRb