/** * The difference in weeks * * @param DateTime $first - The first date * @param DateTime $second - The second date * * @return float */ public static function datediffInWeeks($first, $second) { if ($first > $second) { return datediffInWeeks($second, $first); } return floor($first->diff($second)->days / 7); }
function datediffInWeeks($date1, $date2) { $first = DateTime::createFromFormat('m/d/Y', $date1); $second = DateTime::createFromFormat('m/d/Y', $date2); if ($date1 > $date2) { return datediffInWeeks($date2, $date1); } return floor($first->diff($second)->days / 7); }