Re: Date Math

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 11:40 AM -0400 4/20/10, Floyd Resler wrote:
I need to get the difference in months between two dates. The dates could be as much as 60 months apart. Is there any easy way to do this either through PHP or MySQL? I know how I can do it through code but thought there might be a simple one or two line option.

Thanks!
Floyd



<?php

$date1 = '2009-02-27';
$date2 = '2004-12-03';

$udate1 = strtotime($date1);
$udate2 = strtotime($date2);

$difference = $udate1 - $udate2;

$months_difference = floor($difference / 2678400);

echo("The difference is $months_difference months");

?>

I this will work, but the question of what constitutes a month might come into play.

Cheers,

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux