PHP Gets the Date Range of the Current Week (Month)_PHP Tutorial

WBOY
Release: 2016-07-13 10:22:49
Original
1043 people have browsed it

PHP Gets the date range of the current week (month)

The program needs to write a method to get the date range of the current week, that is, the date range from Monday to Sunday.

Function getWeekRange($date){

 $ret=array();

$timestamp=strtotime($date);

 $w=strftime('%u',$timestamp);

$ret['sdate']=date('Y-m-d 00:00:00',$timestamp-($w-1)*86400);

$ret['edate']=date('Y-m-d 23:59:59',$timestamp+(7-$w)*86400);

return $ret;

 }

//author:zhxia Get the start date and end date of the month where the specified date is located

Function getMonthRange($date){

 $ret=array();

$timestamp=strtotime($date);

$mdays=date('t',$timestamp);

$ret['sdate']=date('Y-m-1 00:00:00',$timestamp);

 $ret['edate']=date('Y-m-'.$mdays.' 23:59:59',$timestamp);

return $ret;

 }

//author:zhxia Application of the above two functions

Function getFilter($n){

 $ret=array();

switch($n){

Case 1:// Yesterday

 $ret['sdate']=date('Y-m-d 00:00:00',strtotime('-1 day'));

$ret['edate']=date('Y-m-d 23:59:59',strtotime('-1 day'));

break;

Case 2://This week

$ret=getWeekRange(date('Y-m-d'));

break;

case 3://last week

$strDate=date('Y-m-d',strtotime('-1 week'));

 $ret=getWeekRange($strDate);

break;

Case 4: //Last week

$strDate=date('Y-m-d',strtotime('-2 week'));

 $ret=getWeekRange($strDate);

break;

Case 5: //This month

$ret=getMonthRange(date('Y-m-d'));

break;

Case 6://Last month

$strDate=date('Y-m-d',strtotime('-1 month'));

 $ret=getMonthRange($strDate);

break;

 }

return $ret;

 }

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/847199.htmlTechArticlePHP needs to get the date range of the current week (month). I wrote a program to get the date range of the current week, also That is the date range from Monday to Sunday. function getWeekRang...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!