Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,851 questions

51,772 answers

573 users

How to create an array of dates between a start and end date in PHP

1 Answer

0 votes
$start = new DateTime('2020-5-15');
$end = new DateTime('2020-5-21');
$end = $end->modify('+1 day');

$interval = new DateInterval('P1D');
$period = new DatePeriod($start, $interval ,$end);

foreach($period as $d){
    echo $d->format("Y-m-d") . "\n";
}


/*
run:

2020-05-15
2020-05-16
2020-05-17
2020-05-18
2020-05-19
2020-05-20
2020-05-21

*/

 



answered May 21, 2020 by avibootz
...