Home >Backend Development >PHP Tutorial >How to get the start date and end date of this week in php_PHP tutorial

How to get the start date and end date of this week in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:04:22787browse

How to get the start date and end date of this week in php

This article mainly introduces the method of getting the start date and end date of this week in php, and analyzes the php operation date with examples. The skills have certain reference value. Friends in need can refer to it

The example in this article describes how to get the start date and end date of this week in php. Share it with everyone for your reference. The details are as follows:

The code is as follows:

//Current date
$sdefaultDate = date("Y-m-d");
//$first =1 means every Monday is the starting date, 0 means every Sunday is the starting date
$first=1;
//Get the day of the current week. Sunday is 0, Monday to Saturday is 1 - 6
$w=date('w',strtotime($sdefaultDate));
//Get the start date of this week. If $w is 0, it means Sunday, minus 6 days
$week_start=date('Y-m-d',strtotime("$sdefaultDate -".($w ? $w - $first : 6).' days'));
//End date of this week
$week_end=date('Y-m-d',strtotime("$week_start +6 days"));

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/965531.htmlTechArticleHow to get the start date and end date of this week in php This article mainly introduces how to get the start date and end date of this week in php The method of ending date, an example analysis of the skills of operating dates in PHP, has certain...
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