Home >Backend Development >PHP Tutorial >How to Get the First Day of the Current Week in PHP?

How to Get the First Day of the Current Week in PHP?

Barbara Streisand
Barbara StreisandOriginal
2024-11-30 21:55:12354browse

How to Get the First Day of the Current Week in PHP?

Get First Day of Current Week in PHP

Determining the first day of the current week is a common task when working with dates. In PHP, you can use a combination of date functions to achieve this:

Solution:

$day = date('w');
$week_start = date('m-d-Y', strtotime('-'.$day.' days'));

Here, $day represents the current day of the week, ranging from 0 (Sunday) to 6 (Saturday). By subtracting $day from the current date using strtotime(), we get the date of the previous Sunday, which is the first day of the current week.

The above is the detailed content of How to Get the First Day of the Current Week in PHP?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn