PHP application for obtaining the date list 30 days before the current date

Source: Internet
Author: User

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 ++) {// The number here is changed as needed

$ Days [] = date ("Y-m-d", strtotime ('-'. $ I. 'day '));

} // Http://www.Alixixi.com/php-function/970.html

Echo'

'; 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

)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.