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 Link to comment https://forums.phpfreaks.com/topic/48832-month-difference/ 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. Link to comment https://forums.phpfreaks.com/topic/48832-month-difference/#findComment-239336 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 ?> Link to comment https://forums.phpfreaks.com/topic/48832-month-difference/#findComment-239360 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.