Home > Backend Development > PHP Tutorial > PHP获取当前日期前n天日期列表的方法

PHP获取当前日期前n天日期列表的方法

WBOY
Release: 2016-06-20 13:02:38
Original
1336 people have browsed it

php的strtotime这个函数,strtotime('n day')获取当前日期前n天日期,示例如下:

<p>$days=array();</p>for($i=0;$i<=7;$i++){//这里数字根据需要变动<br />	$days[]=date("Y-m-d",strtotime('-'.$i.'day'));<br />}//http://www.scutephp.com/<br /><p>echo '<pre class="brush:php;toolbar:false">';print_r($days);</p>
Copy after login

结果将显示如下:

Array

(
    [0] => 2014-03-21
    [1] => 2014-03-20
    [2] => 2014-03-19
    [3] => 2014-03-18
    [4] => 2014-03-17
    [5] => 2014-03-16
    [6] => 2014-03-15
    [7] => 2014-03-14
)


Related labels:
source:php.cn
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