<?phpheader (' content-type:text/html; Charset=utf-8 '); $date =date (' y-m-d '); Current date $first=1; $first =1 represents the start date of the week Monday for the beginning of 0 per Sunday for the start date $w=date (' W ', Strtotime ($date)); Get the day of the current week Sunday is 0 weeks a to Saturday is 1-6 $now _start=date (' y-m-d ', Strtotime ("$date-". $w? $w-$first: 6). ' Days '); Gets the start date of the week, if $w is 0, then represents Sunday, minus 6 $now_end=date (' y-m-d ', Strtotime ("$now _start +6 Days"); This week's End date $last_start=date (' y-m-d ', Strtotime ("$now _start-7 Days")); Last week start date $last_end=date (' y-m-d ', Strtotime ("$now _start-1 Days")); Last week End date echo ' This week start date: ', $now _start, ' <br/> '; Echo ' This week's End date: ', $now _end, ' <br/> '; Echo ' last week start date: ', $last _start, ' <br/> '; Echo ' last week's End date: ', $last _end, ' <br/> ';
Note: Since the foreign week begins in Sunday, the Chinese habit starts from Monday, so the direct use of Strtotime ("last Monday") will result in incorrect results.
PHP gets the start date and end date for this week and last week