How can we get the next 12 months from this month? How can we get the next 12 months from this month? I am using PHPcodefor ($ I = 1; $ I & lt; = 12; $ I ++) {$ nextdate = date (& quot; y-m & quot;, strtotime (& quot; + $ imonth & quot;); echo how to obtain the next 12 months from this month?
How can we get the next 12 months from this month?
I am using:
PHP code
for($i=1;$i<=12;$i++){ $nextdate = date("Y-m",strtotime("+ $i month")); echo ''.$nextdate;}
It seems that there is no problem. you can print it and find that the February is repeated. I don't know why.
2009-11
2009-12
2010-01
2010-03
2010-03
2010-04
2010-05
2010-06
2010-07
2010-08
2010-09
2010-10
------ Solution --------------------
Because your month is calculated by 30 days, and some months are calculated by 28 days, it is wrong to wait until February.
------ Solution --------------------
PHP code
// The parameter indicates multiple months. you can also change it to function c ($ num = 12) {$ temp = array () on the specified date (); $ nowtime = strtotime (date ('Y-M', time ()). '-1'); while ($ num> 0) {$ num --; $ nowtime = strtotime (' + 1 month', $ nowtime ); $ temp [] = date ('Y-M', $ nowtime);} unset ($ num, $ nowtime); return $ temp;} print_r (c ());