php获取本周开始日期和结束日期的方法_PHP

WBOY
Release: 2016-05-31 13:13:32
Original
1064 people have browsed it

本文实例讲述了php获取本周开始日期和结束日期的方法。分享给大家供大家参考。具体如下:

代码如下:

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

希望本文所述对大家的php程序设计有所帮助。

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