Recently, the project requires a statistical function to count the records of the first 30 days before the current date. The function is quite simple. I will share with you the implementation method below to make it easy for anyone who needs it.
In fact, the strtotime function of php is mainly used, strtotime ('n Day'). The example is as follows:
$ Days = array (); for ($ I = 0; $ I <= 7; $ I ++) {// here the number is changed as needed $ days [] = date ("Y-m-d", strtotime ('-'. $ I. 'day');} // http://www.phpernote.com/php-function/970.htmlecho '<pre>'; print_r ($ days );
The result is 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 does PHP obtain the date list for a period of time?
- Reasons why PHP adds a backslash before the quotation mark and how PHP removes the backslash, there are three ways to disable the php magic quotation mark
- JavaScript retrieves the current date and time and displays the day of the week at the same time
- PHP obtains the week of the specified date, the first day of the month and the last day of the month.
- Php calculates the number of days of the difference between two dates.
- Php obtains the start time and end time timestamp of the week of the specified date.
- How to obtain information about the Year, Zodiac, and constellation of the rule by using the date or timestamp in php
- Php extracts the birthday date from the ID card number and verifies whether it is a minor.