Avatar of tonelm54
tonelm54
 asked on

Get array of months between 2 dates

Im trying to get a list of months between 2 dates, and came up with:-

        function echoDate( $start, $end ){
            $current = $start;             $ret = array();             while( $current<$end ){                 $next = date('Y-M-01', $current) . "+1 month";                 $current = strtotime($next);                 $ret[] = date("Y-m",$current);             }             return $ret;         }

Open in new window

So, if I ran:-

echoDate(strtotime("2021-09-06"), strtotime("2021-12-26"));

Open in new window

I should get an array of:-

2021-09
2021-10
2021-11
2021-22

Open in new window

But instead I get an array of:-

2021-10
2021-11
2021-12
2022-01

Open in new window

Which I dont understand of where its getting these values from.


Any ideas?

PHP

Avatar of undefined
Last Comment
Ryan Chong

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Ryan Chong

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Your help has saved me hundreds of hours of internet surfing.
fblack61