//The first and last day of this week
Copy code The code is as follows:
$date=new DateTime() ;
$date->modify('this week');
$first_day_of_week=$date->format('Y-m-d');
$date->modify('this week +6 days');
$end_day_of_week=$date->format('Y-m-d');
After testing, I don’t know what modity is used for, so I found it Another two examples
Copy code The code is as follows:
//Monday of this week
// @$ timestamp, a timestamp of a certain week, defaults to the current time
// @is_return_timestamp, whether to return a timestamp, otherwise return the time format
function this_monday($timestamp=0,$is_return_timestamp=true){
static $cache ;
$id = $timestamp.$is_return_timestamp;
if(!isset($cache[$id])){
if(!$timestamp) $timestamp = time() ;
$monday_date = date('Y-m-d', $timestamp-86400*date('w',$timestamp)+(date('w',$timestamp)>0?86400:-/*6 *86400*/518400));
if($is_return_timestamp){
$cache[$id] = strtotime($monday_date);
}else{
$cache[$id] = $ monday_date;
}
}
return $cache[$id];
}
//Sunday of this week
Copy code The code is as follows:
// @$timestamp, a timestamp of a certain week, the default is the current time
// @is_return_timestamp, whether Return timestamp, otherwise return time format
function this_sunday($timestamp=0,$is_return_timestamp=true){
static $cache;
$id = $timestamp.$is_return_timestamp;
if(! isset($cache[$id])){
if(!$timestamp) $timestamp = time();
$sunday = this_monday($timestamp) + /*6*86400*/518400;
if($is_return_timestamp){
$cache[$id] = $sunday;
}else{
$cache[$id] = date('Y-m-d',$sunday);
}
}
return $cache[$id];
}
http://www.bkjia.com/PHPjc/825315.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825315.htmlTechArticle//Copy the code for the first and last day of this week The code is as follows: $date=new DateTime(); $date-modify('this week'); $first_day_of_week=$date-format('Y-m-d'); $date-modify('this week +6...