How to Retrieve the First Day of the Week in PHP
Determining the first day of the week can be essential for date-related applications. In PHP, this task can be effortlessly accomplished using built-in date functions.
Method:
To retrieve the first day of the week for a given date in MM-dd-yyyy format, follow these steps:
Determine the Day of the Week:
Calculate the First Day of the Week:
Format the Result:
Example Code:
The following code demonstrates how to implement the above method:
$day = date('w'); $week_start = date('m-d-Y', strtotime('-'.$day.' days'));
The variable $week_start will now hold the date for the previous Sunday, which is the first day of the current week.
Additional Notes:
The above is the detailed content of How to Get the First Day of the Week in PHP?. For more information, please follow other related articles on the PHP Chinese website!