3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function monthsBetween($startDate, $endDate) { $retval = ""; // Assume YYYY-mm-dd - as is common MYSQL format $splitStart = explode('-', $startDate); $splitEnd = explode('-', $endDate); if (is_array($splitStart) && is_array($splitEnd)) { $difYears = $splitEnd[0] - $splitStart[0]; $difMonths = $splitEnd[1] - $splitStart[1]; $difDays = $splitEnd[2] - $splitStart[2]; $retval = ($difDays > 0) ? $difMonths : $difMonths - 1; $retval += $difYears * 12; } return $retval; } echo monthsBetween('2014-06-16','2015-05-16'); ?>
based on 3mXh6
Output for 4.3.0 - 7.2.0
10