PHP implementation to get the start date and end date of this week

小云云
Release: 2023-03-22 06:26:01
Original
3902 people have browsed it

This article mainly shares with you the PHP implementation of getting the start date and end date of this week. It is mainly shared with you in the form of code. I hope it can help everyone.

<?php

//当前日期
$sdefaultDate = date("Y-m-d");
//$first =1 表示每周星期一为开始日期 0表示每周日为开始日期
$first=1;
//获取当前周的第几天 周日是 0 周一到周六是 1 - 6
$w=date(&#39;w&#39;,strtotime($sdefaultDate));
//获取本周开始日期,如果$w是0,则表示周日,减去 6 天
$week_start=date(&#39;Y-m-d&#39;,strtotime("$sdefaultDate -".($w ? $w - $first : 6).&#39; days&#39;));
//本周结束日期
$week_end=date(&#39;Y-m-d&#39;,strtotime("$week_start +6 days"));
echo "$week_start"."$week_end";
Copy after login

Related recommendations:

php method to get the start date and end date of this week, php start date_PHP tutorial

The above is the detailed content of PHP implementation to get the start date and end date of this week. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template