/**
* takes two dates and returns an array of dates between them
*
* @param date1 The start date of the period.
* @param date2 The end date of the period.
* @param format The format of the date you want to display.
*
* @return array array of dates between the two dates.
*/
function displayDatePeriod( $date1, $date2 , $format = "Y-m-d"){
$periodArray = [];
$period =
new DatePeriod(
new DateTime($date1),
new DateInterval('P1D'),
new DateTime($date2)
);
foreach ($period as $key => $value) {
$periodArray[] = $value->format($format) ;
}
$periodArray[] = $date2 ;
return $periodArray;
}
1
how to calculate days difference between two dates in php
// how to calculate days difference between two dates in laravel
use DateTime; // inside Controller Class
$startDate = new DateTime($request->start_date);
$endDate = new DateTime($request->end_date);
$daysDifference = ($startDate->diff($endDate)->days);
$period = new DatePeriod(
new DateTime('2010-10-01'),
new DateInterval('P1D'),
new DateTime('2010-10-05')
);
//Which should get you an array with DateTime objects.
//To iterate
foreach ($period as $key => $value) {
//$value->format('Y-m-d')
}
$period = new DatePeriod(
new DateTime('2010-10-01'),
new DateInterval('P1D'),
new DateTime('2010-10-05')
);
foreach ($period as $key => $value) {
//$value->format('Y-m-d')
}