I want to get dates between two dates in an array. The scenario is the following: I want to get daily sales cash collection and there is one filter of $fromdate
and $todate
. So even if I don't get any sales for an specific date I have to show that in the table.
Asked
Active
Viewed 2,382 times
-1

allexiusw
- 1,533
- 2
- 16
- 23

prem thakkar
- 1
- 5
2 Answers
0
You can use CarbonPeriod for this.
I found something helpful at https://stackoverflow.com/a/50854594/13642447.

theleader22
- 91
- 6
0
Use DatePeriod class to create the range of dates based on months or days
<?php
$begin = new DateTime( '2012-08-01' );
$end = new DateTime( '2013-10-31' );
$interval = new DateInterval('P1M');
$daterange = new DatePeriod($begin, $interval ,$end);
$dates = [];
foreach($daterange as $date){
$dates[] = $date->format("Y-m-d");
}
var_dump($dates);
?>
if you want the range of dates to be by days, say from 2012-08-01
to 2012-08-25
then just change the interval like this $interval = new DateInterval('P1D');
.

Hardood
- 503
- 1
- 5
- 15