PHP gets a list of dates 30 days before the current date

Source: Internet
Author: User
Tags date array end

Recently, as a result of the project requirements to do a statistical function, the current date before the first 30 days of records. function quite simple, the following will be the realization of the method and share with you, to facilitate the needs of friends.

In fact, the main thing is to use the PHP strtotime this function, Strtotime (' N Day '), examples are as follows:

$days =array ();
For ($i =0 $i <=7; $i + +) {//Here the number changes according to need
	$days []=date ("y-m-d", Strtotime ('-'. $i. ')
} Http://www.Alixixi.com/php-function/970.html
Echo ' <pre> ';p rint_r ($days);

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 that you may be interested in

    • How PHP gets a list of dates for a period of time
    • PHP in front of quotes to add the reason for the backslash and PHP to remove the backslash, three ways to turn off the PHP magic quotes
    • JavaScript gets the current date time and displays the day of the week
    • PHP gets the start and end dates for this week and last week
    • PHP gets the timestamp of the start and end times of the week that the specified date is in
    • PHP gets the specified date of the week, the first and last day of the month
    • PHP calculates a function of how many days (day) difference two dates
    • PHP extracts the birthday date in the ID number and the function to verify that it is a minor


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.