How to Get the First Date of a Week in PHP?

Problem:

You have a date(ex. 2001-09-11) and you want to find out the the first date of the week of that date.

Solution:

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.

first date of a week

<?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 />";
?>

[wpdm_file id=109]

Output:
First date of the week of Sep 11, 2001 is: 09-10-2001.

Please remember following two things when dealing with weeks in PHP.

  1. The week starts from Sunday and ends at Saturday next.
  2. By default, Monday is considered as the first day of the week.