<?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