Log in

View Full Version : How to get PHP Countdown Script into London Timezone



Ryan Fitton
02-04-2009, 10:15 AM
I i have created this php countdown script but im unsure how to get it into the london timezone because it is based on the PHP servers current timezone. For example it changes the day even when its only about 9:00PM in London.



<?php
//A: RECORDS TODAY'S Date And Time
$today = time();

//B: RECORDS Date And Time OF YOUR EVENT
$event = mktime(0,0,0,02,15,2009);

//C: COMPUTES THE DAYS UNTIL THE EVENT.
$countdown = round(($event - $today)/86400);

//D: DISPLAYS COUNTDOWN UNTIL EVENT
echo "$countdown days until New York trip";
?>

Schmoopy
02-04-2009, 10:45 AM
You can use the date_default_timezone_set() (http://uk.php.net/manual/en/function.date-default-timezone-set.php) function. Modify your code like this:



<?php
// Set server time to that in London
date_default_timezone_set('Europe/London');

//A: RECORDS TODAY'S Date And Time
$today = time();

//B: RECORDS Date And Time OF YOUR EVENT
$event = mktime(0,0,0,02,15,2009);

//C: COMPUTES THE DAYS UNTIL THE EVENT.
$countdown = round(($event - $today)/86400);

//D: DISPLAYS COUNTDOWN UNTIL EVENT
echo "$countdown days until New York trip";
?>

Ryan Fitton
02-04-2009, 10:57 AM
Thanks Schmoopy

:)

Ryan Fitton
02-04-2009, 12:27 PM
Sorry but I have just found a problem with the script. Because when it counts down the days it is supposed to change at 12:00AM in the moring but i have just seen it has changed at 12:00PM in the afternoon, why has it done this even with the timezone.