<?php function diffInMonth(DateTime $start,DateTime $end): int { list($yearStart,$monthStart,$dayStart) = explode(" ",$start->format("Y m dHis")); list($yearEnd,$monthEnd, $dayEnd) = explode(" ",$end->format("Y m dHis")); $mothDiff = ($yearEnd - $yearStart) * 12 + $monthEnd - $monthStart; if($dayStart > $dayEnd) --$mothDiff; return $mothDiff; } $startDate = new DateTime('2022-11-01 00:00:00.0', new DateTimeZone('Africa/Nairobi')); $endDate = new DateTime('2022-12-01 00:00:00.0', new DateTimeZone('Africa/Nairobi')); $month = diffInMonth($startDate, $endDate); echo $month;
You have javascript disabled. You will not be able to edit any code.