PHP: Get month difference between two timestamps
<?php
/**
* Calculates how many months is past between two timestamps.
*
* @param int $start Start timestamp.
* @param int $end Optional end timestamp.
*
* @return int
*/
function get_month_diff($start, $end = FALSE)
{
$end OR $end = time();
$start = new DateTime("@$start");
$end = new DateTime("@$end");
$diff = $start->diff($end);
return $diff->format('%y') * 12 + $diff->format('%m');
}