Home  >  Article  >  Backend Development  >  PHP application to get the date list 30 days before the current date_PHP tutorial

PHP application to get the date list 30 days before the current date_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:27:48919browse

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

 )

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/814684.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...
Statement:
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