# How to get the next 12 months from this month

Source: Internet
Author: User
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 ());`
Related Keywords:

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.