web2000 Posted April 26, 2007 Share Posted April 26, 2007 Hello, I am trying to work out the difference in months between 2 dates, can anyone help? Thanks Quote Link to comment Share on other sites More sharing options...
per1os Posted April 26, 2007 Share Posted April 26, 2007 llewellyntd at gmail dot com 29-Apr-2005 08:50 Here is a very easy way to get the difference, in days, between two dates: $days = (strtotime("2005-12-31") - strtotime(date("Y-m-d"))) / (60 * 60 * 24); print $days; Found in user comments at www.php.net/date <?php $date_start = "04/01/2005"; $date_end = "06/01/2005"; $months = ((strtotime($date_start) - strtotime($date_end))/(3600*24*30)); print $months; ?> Untested, the only issue is the amount of days some months can have, this is assuming all months have 30 days. Quote Link to comment Share on other sites More sharing options...
Barand Posted April 26, 2007 Share Posted April 26, 2007 <?php $d1 = strtotime('2005-06-01'); $d2 = strtotime('2007-04-25'); $y1 = date('Y', $d1); $y2 = date('Y', $d2); $m1 = date('n', $d1); $m2 = date('n', $d2); $month_diff = ($y2 - $y1) * 12 + ($m2 - $m1); echo $month_diff; // 22 ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.