PHP gets the first and last day of the week sample code

Source: Internet
Author: User
Tags current time

  This article mainly introduces the way PHP gets the first and last day of the week, and the friends you need can refer to the following

The first and last day of the week     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 ');    tested modity did not know what to do, in the time to find another two examples   code as follows://This week's Monday  //@ $timestamp, a certain time stamp of a week, the default is the current time & nbsp @is_return_timestamp, whether to return a timestamp, otherwise return 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) + (' W ', $ Timestamp) >0?86400:-/*6*86400*/518400);  if ($is _return_timestamp) {  $cache [$id] = Strtotime ($monday _ Date); }else{  $cache [$id] = $monday _date; } }  return $cache [$id]; }   //This The Sunday     code for the week is as follows://@ $timestamp, a time stamp for a week, the default is the current time  //@is_retUrn_timestamp, whether to 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]; }&NB Sp
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.