Upgrade to Chess.com Premium!

Calculating the difference between two dates using php.

Hey 01000111011101010111100101110011 (Guys), and 0100011101101001011100100110110001110011 (Girls),

I have recently been  searching the relms of the interwebs for a nice clean date difference calculator, that was built on php. This was too no avail i eventually got fed up with the search and decided screw it i will do this myself. So the following is a really simple calculator that can be used to determine the difference between two dates in hours. :)

 

 function dateDiff($a, $b)

{

 $one_hour = 60*60; // Number of seconds in an hour used to convert to hours. 

$start = strtotime($a); // Returns the unix timestamp for a specific real date.

$end = strtotime($b);

$dif = floor(($end - $start)/$one_hour); // Determines the number of hours between two dates. 

return $dif; // Returns the difference. :) 

}

 

I hope this helps someone eventually. :)

Joshua

Comments


  • 9 months ago

    killthequeen

    Will this work over the space of a few years? Or just for dates in a single non-leap year. Thanks, hope Melbourne is going well for you Josh. Also I beat an IM in 1 minute :D

Back to Top

Post your reply: