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,895 questions

51,826 answers

573 users

How to generate a range of dates that jump 1 month each time in PHP

1 Answer

0 votes
date_default_timezone_set('UTC');

$start_date = '2010-01-31';
$end_date = '2010-12-31';

while (strtotime($start_date) <= strtotime($end_date)) {
            echo "$start_date\n"; 
            $d = new DateTime($start_date);
            $d->modify('last day of next month');
            $start_date = $d->format('Y-m-d');
}
   
   

/*
run:

2010-01-31
2010-02-28
2010-03-31
2010-04-30
2010-05-31
2010-06-30
2010-07-31
2010-08-31
2010-09-30
2010-10-31
2010-11-30
2010-12-31

*/

 



answered Jun 11, 2020 by avibootz
...