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 method of implementation 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++){//The number here changes as needed
$days[]=date("Y-m-d",strtotime('-'.$i.'day'));
}//http://www.Alixixi.com/php-function/970.html
echo '
;print_r($days);
The results will be displayed 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
)