PHP retrieves the date of today, yesterday, and tomorrow

Source: Internet
Author: User
: This article describes how to obtain the date of today, yesterday, and tomorrow for PHP. For more information about PHP tutorials, see. Directly go to the code and explain

 "; Echo" yesterday: ". date (" Y-m-d ", strtotime ("-1 day ")),"
"; Echo" tomorrow: ". date (" Y-m-d ", strtotime (" + 1 day "))."
"; Echo" one week later: ". date (" Y-m-d ", strtotime (" + 1 week "))."
"; Echo" one week, two days, four hours, two seconds later :". date ("Y-m-d G: H: s", strtotime ("+ 1 week 2 days 4 hours 2 seconds "))."
"; Echo" next Thursday: ". date (" Y-m-d ", strtotime (" next Thursday "))."
"; Echo" last Monday: ". date (" Y-m-d ", strtotime (" last Monday "))."
"; Echo" a month ago: ". date (" Y-m-d ", strtotime (" last month "))."
"; Echo" one month later: ". date (" Y-m-d ", strtotime (" + 1 month "))."
"; Echo" Ten years later: ". date (" Y-m-d ", strtotime (" + 10 year "))."
";?>

The strtotime () function is used to parse the description of the date and time to the Unix timestamp int strtotime (string time [, int now]) PHP day of the week to obtain the code: date ("l "); // data can be used to obtain the week in English, for example, Sundaydate ("w"); // This can be used to obtain the number of weeks, for example, 123, note that 0 is a Chinese Week on Sunday. $ weekarray = array ("day", "1", "2", "3", "4", "5 ", "6"); echo "week ". $ weekarray [date ("w")]; get the specified date: $ weekarray = array ("day", "one", "two", "three ", "4", "5", "6"); echo "week ". $ weekarray [date ("w", "2011-11-11")]; because the date function is very powerful, he is fully qualified for all such work. I have attached a table in the manual, A-"am", "pm" a-"AM", or "PM" d-A few days, two digits. if there are less than two digits, the first digit is zero. for example, "01" to "31" D-Day of the week, three English letters. for example, "Fri" F-month, full English name, for example, "January" h-12 hours; for example, "01" to "12" H-24 hours; for example: "00" to "23" g-12 hours, less than two do not fill zero; for example: "1" to 12 "G-24 hours, for example, "0" to "23" I-minutes; for example, "00" to "59" j-days, two digits. if the remaining two digits are not zero; for example: "1" to "31" l-the day of the week, full name in English; for example: "Friday" m-month, two digits. if less than two digits are left blank in front, for example: "01" to "12" n-month, two digits, if less than two digits, do not fill in zero; for example, "1" to "12" M-month, three English letters; for example: "Jan" s-seconds; for example: "00" to "59" S-end with an English sequence, two English letters; for example: "th ", "nd" t-specifies the number of days of the month. for example, "28" to "31" U-total number of seconds w-number of the day of the week, for example, "0" (Sunday) to "6" (Saturday) Y-year, four digits, for example, "1999" y-year, two digits, for example, "99" z-the day of the year; for example, "0" to "365"

The above describes how PHP can get the date of today, yesterday, and tomorrow, including some content, and hope to help those who are interested in PHP tutorials.

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.