get amount of days between two dates php code example
Example 1: php get date between two dates
$period = new DatePeriod(
new DateTime('2010-10-01'),
new DateInterval('P1D'),
new DateTime('2010-10-05')
);
foreach ($period as $key => $value) {
}
Example 2: php calculate weeks between two dates
function numWeeks($dateOne, $dateTwo){
$firstDate = new DateTime($dateOne);
$secondDate = new DateTime($dateTwo);
$differenceInDays = $firstDate->diff($secondDate)->days;
$differenceInWeeks = $differenceInDays / 7;
return floor($differenceInWeeks);
}
$numOfWeek = numWeeks('2021-01-21', '2021-01-28');