Home > Backend Development > PHP Tutorial > PHP遍历月度可以做到吗

PHP遍历月度可以做到吗

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 12:26:05
Original
868 people have browsed it

PHP遍历月份可以做到吗?
比如我已知
起始月份2014-08-12
截止月份2015-10-20

遍历这个时间段的月历
例如:
2014-08
2014-09
2014-10
2014-11
2014-12
2015-01
2015-02
。。。。。
2015-10




------解决思路----------------------

<br />$startdate = '2014-08-12';<br />$enddate = '2015-10-20';<br /><br />$s = strtotime($startdate);<br />$e = strtotime($enddate);<br /><br />$num = (date('Y',$e)-date('Y',$s)-1)*12+(12-date('m',$s)+1)+date('m',$e);<br /><br />$months = array();<br />for($i=0; $i<$num; $i++){<br />    $d = mktime(0,0,0,date('m',$s)+$i,date('d',$s),date('Y',$s));<br />    $months[] = date('Y-m',$d);<br />}<br /><br />print_r($months);<br />
Copy after login



Array
(
    [0] => 2014-08
    [1] => 2014-09
    [2] => 2014-10
    [3] => 2014-11
    [4] => 2014-12
    [5] => 2015-01
    [6] => 2015-02
    [7] => 2015-03
    [8] => 2015-04
    [9] => 2015-05
    [10] => 2015-06
    [11] => 2015-07
    [12] => 2015-08
    [13] => 2015-09
    [14] => 2015-10
)

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template