PHP obtains the sample code on the first and last days of the week. The code for copying the first and last days of this week is as follows: $ datenewDateTime (); $ date-modify (thisweek); $ first_day_of_week $ date-format (Y-m-d ); $ date-modify (thisweek + 6 // The first and last days of the 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 days ');
$ End_day_of_week = $ date-> format ('Y-m-D ');
After testing modity, I did not know what to do. I found another two examples.
The code is as follows:
// Monday of the week
// @ $ Timestamp, a timestamp of a week. The default value is the current time.
// @ Is_return_timestamp, whether to return the timestamp; otherwise, the 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) + (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 the week
The code is as follows:
// @ $ Timestamp, a timestamp of a week. The default value is the current time.
// @ Is_return_timestamp, whether to return the timestamp; otherwise, the 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) +/* 6x86400 */518400;
If ($ is_return_timestamp ){
$ Cache [$ id] = $ Sunday;
} Else {
$ Cache [$ id] = date ('Y-m-D', $ Sunday );
}
}
Return $ cache [$ id];
}
The expiration 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...