<?php
$fromDate = ’01/01/2009′;
$toDate = ’01/10/2009′;
$dateMonthYearArr = array();
$fromDateTS = strtotime($fromDate);
$toDateTS = strtotime($toDate);
for ($currentDateTS = $fromDateTS; $currentDateTS <= $toDateTS; $currentDateTS += (60 * 60 * 24)) {
// use date() and $currentDateTS to format the dates in between
$currentDateStr = date(“Y-m-d”,$currentDateTS);
$dateMonthYearArr[] = $currentDateStr;
//print $currentDateStr.”<br />”;
}
echo “<pre>”;
print_r($dateMonthYearArr);
echo “</pre>”;
?>
OR
function get_months($date1, $date2) {
$time1 = strtotime($date1);
$time2 = strtotime($date2);
$my = date(‘mY’, $time2);
$months = array(date(‘F Y’, $time1));
while($time1 < $time2) {
$time1 = strtotime(date(‘Y-m-d’, $time1).’ +1 month’);
if(date(‘mY’, $time1) != $my && ($time1 < $time2))
$months[] = date(‘F Y’, $time1);
}
$months[] = date(‘F Y’, $time2);
return $months;
}
echo “<pre>”; print_r(get_months(’2011-02-1′, ’2012-12-1′)); echo “</pre>”;
Thanks,
Nilesh Prajapati.
Good Work
Thank you
By: sreeja on May 22, 2009
at 10:48 am
Very useful. Your help is appreciated.
By: senthil on July 17, 2009
at 5:55 am
Very Thnx dear! gud wrk………….
By: Amardeep Singh on July 27, 2009
at 5:44 pm
Thanks ,good coding
By: milind Morey on August 13, 2009
at 8:07 am
Its helpful to me… thanks
By: Hyder on September 9, 2009
at 10:35 am
$(“body”).css({“display”:”none”})
By: fghfh on November 23, 2011
at 7:03 am
Thanks Dear, Nice coding.
By: Pukhraj on November 2, 2009
at 5:54 am
But this does take care of daylight saving problem..
i.e this year 2009 1st November is echoed twice..(In Daylight saving time zones)
By: Vinod on November 16, 2009
at 11:38 am
I meant it does not solve the DST problem
By: Vinod on November 16, 2009
at 11:39 am
Thanx Dear……..nice code……appropriate to use…..
By: Sheeraz on January 15, 2010
at 1:44 pm
thaks frd
By: anurudh on March 14, 2010
at 4:24 pm
Thanks buddy ur answer is so useful
By: rohit prajapati on April 16, 2010
at 7:11 am
Very useful stuff. Your help is appreciated good work.
By: Narendra Padala on May 29, 2010
at 7:34 am
nice code
By: sourav on June 14, 2010
at 11:00 am
works like a charm. thank you
By: jairuz on August 3, 2010
at 2:08 am
$fromDate = ’01/01/2009′;
$toDate = ’01/10/2009′;
Instead of the above if I give the dates in the form below
$fromDate = ’01-01-2009′;
$toDate = ’01-10-2009′;
it will take d-m-Y format…and naturally gives wrong out put..but still it is helpful for me.Thank you
By: Debraj Roy on August 12, 2010
at 5:11 pm
THANKS A LOT!!!
By: Jhon on September 29, 2010
at 12:17 am
very thank
By: tsawm shayi on October 11, 2010
at 8:32 am
Very useful stuff. Your help is appreciated good work.
By: Rajender on November 3, 2010
at 4:11 am
Thanks for the snippet. It was very helpful.
By: Fawaz on February 3, 2011
at 6:29 am
Great script! Thank you for posting this.
By: Bobby on March 29, 2011
at 1:54 am
thanks for the simple code.
By: Niharraj on May 4, 2011
at 7:56 am
Thanks bhai.
By: Prashant Prajapati on May 18, 2011
at 12:15 pm
many thanks…this help me
By: riad1181982 on June 27, 2011
at 9:44 am
It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function.
Could you please suggest any other function instead of strtotime()?It is not safe.
By: Sarita on August 2, 2011
at 10:56 am
thanks a lot
By: Sowmya on August 8, 2011
at 11:22 am
terima kasih(Indosesia)/Thank you………
By: Krisnanda on August 24, 2011
at 7:27 am
thanks nice logics:)
By: anuragguatam77Anurag on September 19, 2011
at 8:54 am
Thanks… very useful and simple code.
By: Atheeswaran on September 21, 2011
at 10:20 am
Just what I was looking for thank you 🙂
By: Michael on November 9, 2011
at 9:00 am
this the best code.it is solve my proplem which cannot solve in one day.
By: jyotisman on December 20, 2011
at 12:47 pm
Thanks
By: Amit on December 31, 2011
at 4:32 am
Thankyou for the posting. Very Helpful
By: manisandeep on January 20, 2012
at 12:21 pm
Thank You… It was very useful.
By: Velpandi on January 25, 2012
at 11:16 am
hi…….. its very nice blog
By: test on March 3, 2012
at 9:45 pm
absolutely brilliant…keep up the good work
By: sam on March 5, 2012
at 7:18 pm
I have found a good solution on the site below. Works like charm for me.
http://phphelp.co/2012/03/28/how-to-print-all-the-months-and-years-between-two-dates-in-php/
Or
http://addr.pk/ac8b
By: Aneeq on March 29, 2012
at 10:14 am
Thanks it helps me….
By: sugesh on March 31, 2012
at 1:02 pm
Thanks bro………….It’s very helpful
By: yogesh jangir on April 7, 2012
at 6:10 am
Wow … it’s a very simple script.
By: Saurabh Goyal on May 11, 2012
at 8:59 am
thank you very much…………………………….
By: kapil karma on June 8, 2012
at 10:51 am
thanx….its working!!!!!
By: abhinandan on August 9, 2012
at 5:17 am
nice work nilesh…..
By: dhrumil joshi on September 28, 2012
at 9:51 am
Thanks Nilesh!!!
By: lokesh on June 25, 2013
at 12:10 pm