Web Hosting Talk







View Full Version : Getting the off-set hour between two timezone date


latheesan
03-05-2008, 10:04 PM
Hello,

I am trying to write a simple script that will workout the off-set in hour, between 2 different timezone.

This is how i attempted it :

<?php

$new_tz = 'America/Toronto'; // Based on http://uk3.php.net/manual/en/timezones.america.php

$current_hour = date('h');
date_default_timezone_set($new_tz); // Based on http://uk3.php.net/manual/en/function.date-default-timezone-set.php
$new_hour = date('h');

echo 'Hour Difference : '. ($current_hour - $new_hour);

?>

I ran this script on my local machine (which is in the UK, GMT Timezone). The result i expected to see was -5, because 'America/Toronto' is GMT -5, however, when i ran the script, it outputted -7 (which is wrong).

Where im i going wrong with this?

ilyash
03-05-2008, 10:40 PM
Just a thought, if the the time isnt in 24 hour time.. wouldnt you have to do some sort of date_subtract?

like if it was 12 and 5,... 12-5 = 7
but it's really 5 hours