PHP One line of code to get this Monday, this Sunday, on the Monday, last Sunday, this month, the last day of this month, the end of last month date

Source: Internet
Author: User
Tags echo date
<?php//This Monday echo date (' y-m-d ', (Date (' W ') = 0? 7:date (' W ')-1) * 24 * 3600)); W is the number form of the day of the week, here 0 for Sunday//This Sunday echo date (' y-m-d ', (Time () + (7-(Date (' w ') = = 0 7:date (' W ')) "* 24 * 3600)); The same use W, with Sunday related days to count//Last Monday echo date (' y-m-d ', Strtotime ('-1 Monday ', Time ())); Regardless of today's date, -1 Monday is the last valid week//Last Sunday echo date (' y-m-d ', Strtotime ('-1 Sunday ', Time ()));
Last valid Sunday, same applies to other week//last week Monday to last weekend $time = time ();
$last _monday = Date (' Ymd ', Strtotime ('-1 Monday ', $time));
$last _sunday = Date (' Ymd ', Strtotime ('-1 Sunday ', $time));
if ($last _monday> $last _sunday) {$last _monday = date (' Ymd ', Strtotime ('-2 Monday ', $time));} Echo $last _monday;

echo $last _sunday; This month, echo date (' y-m-d ', strtotime (' Y-m ', Time ()). '-01 00:00:00 ')); Generated directly in Strtotime//Last day of this month echo date (' y-m-d ', strtotime (date (' Y-m ', Time ()). '-' . Date (' t ', Time ()). ' 00:00:00 ')); T is the number of days of the month, 28-31 days//Last month, echo date (' y-m-d ', Strtotime (' 1 month ', Strtotime date (' Y-m ', Time ()). '-01 00:00:00 ')); Direct Strtotime on the day of this month minus one months//last day of the previous month Echo date (' y-m-d ', strtotime (date (' Y-m ', Time ()). '-01 00:00:00 ')-86400);
 The day of the month is the last


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.