You have a date(ex. 2001-09-11) and you want to find out the the first date of the week of that date.
We can utilize strtotime() function to find out the first date of any given date. In the following example, we’ll see how we can find the first date of the week of the date 2001-09-11.
<?php $timestamp = strtotime("this week Sep 11, 2001"); echo “First date of the week of Sep 11, 2001 was: ” . date('m-d-Y',$timestamp) . "<br />"; ?>
First date of the week of Sep 11, 2001 is: 09-10-2001.
Please remember following two things when dealing with weeks in PHP.
- The week starts from Sunday and ends at Saturday next.
- By default, Monday is considered as the first day of the week.