Welcome Guest, Not a member yet? Register   Sign In
PHP 101 - Why is this? Is year 2006 special?
#1

[eluser]taewoo[/eluser]
So I have this code
Code:
<?php

function dateDiff($start, $end)
{
    $start_ts = strtotime($start);
    $end_ts = strtotime($end);

    $diff = $end_ts - $start_ts;
        return $diff;
}

echo dateDiff("2006-04-01 6:00 PM", "2006-04-02 6:00 AM"); // this prints 39600, incorrect
echo dateDiff("2009-04-01 6:00 PM", "2009-04-02 6:00 AM"); // this prints 43200, correct

?>


I am going insane... i can't figure out WHY. There are 86400 seconds in a day (unless of course, April of 2006 had some crazy time warp going on...

ANyone know why?
#2

[eluser]taewoo[/eluser]
Never mind. Calling
Code:
date_default_timezone_set('GMT');

seemed to have solved this issue
#3

[eluser]charlie spider[/eluser]
all of PHP's time and date functions are designed to return non-sensical data for any input involving April Fool's Day. Just for a gaff.




Theme © iAndrew 2016 - Forum software by © MyBB