Home >Backend Development >PHP Tutorial >How to get the start date and end date of this week in php, php start date_PHP tutorial
The example in this article describes the method of getting the start date and end date of this week in php. Share it with everyone for your reference. The details are as follows:
Copy code The code is as follows: //current date
$sdefaultDate = date("Y-m-d");
//$first =1 means every Monday is the starting date, 0 means every Sunday is the starting date
$first=1;
//Get the day of the current week. Sunday is 0, Monday to Saturday is 1 - 6
$w=date('w',strtotime($sdefaultDate));
//Get the start date of this week. If $w is 0, it means Sunday, minus 6 days
$week_start=date('Y-m-d',strtotime("$sdefaultDate -".($w ? $w - $first : 6).' days'));
//End date of this week
$week_end=date('Y-m-d',strtotime("$week_start +6 days"));
I hope this article will be helpful to everyone’s PHP programming design.