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
Release: 2024-11-30 21:55:12
Original
303 people have browsed it

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'));
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template