Recently, the project requires a statistical function to count the records of the previous 30 days before the current date. The function is quite simple. I will share with you the implementation method below for the convenience of friends in need.
In fact, it mainly uses the strtotime function of php, strtotime('n day'), the example is as follows:
$days=array();
for($i=0;$i<=7;$i++){//这里数字根据需要变动
$days[]=date("Y-m-d",strtotime('-'.$i.'day'));
}//http://www.phpernote.com/php-function/970.html
echo '<pre class="brush:php;toolbar:false">';print_r($days);
Copy after login
The results will appear as follows:
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
)
Articles you may be interested in
- How to get a list of dates within a period of time with PHP
- The reason why PHP adds a backslash before the quotation marks And how to remove backslashes in PHP, three ways to turn off php magic quotes
- JavaScript gets the current date and time and displays the day of the week
- PHP gets the week and the first day of the month for the specified date and the last day
- php function to calculate how many days (days) the difference between two dates is
- php gets the timestamp of the start time and end time of the week on the specified date
- php Methods to obtain the chronology, zodiac and constellation information based on date or timestamp
- PHP function to extract the birthday date from the ID number and verify whether it is a minor
http://www.bkjia.com/PHPjc/764087.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/764087.htmlTechArticleRecently, the project requires a statistical function to count the records of the previous 30 days before the current date. The function is quite simple. I will share with you the implementation method this time for your convenience...