Wednesday, 28 August 2013

adding and subtracting dynamic time difference from a set time in PHP?

adding and subtracting dynamic time difference from a set time in PHP?

what I am trying to do might be quite be simple but I don't know how to
get it working.
I did re-search strtotime funtion and read PHP MANUAL
And that led me to the code bellow. I think the fundamental of the code
bellow is correct but the (00:30) is not correct!
Anyway, lets say I have set the time to (00:30) by $strtotime = '00:30';
at the start of the PHP code. now I want to add and/or subtract the
$offset/3600 value from the (00:30).
The $offset/3600 value is a time difference between two timezones if you
are wondering what that is and where its values coming from by the way.
I am trying to use the code bellow:
<?php
$strtotime = '00:30';
if (0 > $offset)
{
// For negative offset (hours behind)
$time = $offset / 3600 + (00:30);
}
elseif (0 < $offset)
{
// For positive offset (hours ahead)
$time - $offset / 3600 - (00:30);
}
else
{
// For offsets in the same timezone.
$time = "in the same timezone as";
}
echo "{$strtotime}";
?>
this code will only echo 00:30 and it wont add or subtract the $offset /
3600 value from it!
is there anything else that i need to do? or I am totally on the wrong path?

No comments:

Post a Comment