How to get the next 12 months from this month

Source: Internet
Author: User
How to get the next 12 months from this month?

How to get the next 12 months from this month?

What I'm using now is:
PHP Code
  
   for ($i =1; $i <=12; $i + +) {    $nextdate = date ("Y-m", Strtotime ("+ $i Month"));    Echo '

'. $nextdate;}



Seems to be no problem, can print but found that March is repeated, I do not 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 28 days in 30 days, so it's not right to wait until February.
------Solution--------------------
PHP Code
The parameter represents a lot of months, you can also modify the Start function c ($num =) {    $temp = array () for 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 ());
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.