Take out this week's Monday and Sunday time stamps

Source: Internet
Author: User
Tags echo date php tutorial

Method One
<?php Tutorial
Echo Strtotime (' last Monday ');
echo ' <br/> ';
Echo Strtotime (' next Sunday ');
?>

Method Two
?

The function Getmonsun () {

$curTime =time ();

04

$curWeekday = Date (' W ');

06

07/0 is the week Seven

$curWeekday = $curWeekday $curWeekday: 7;

09

10

One $curMon = $curTime-($curWeekday-1) *86400;

$curSun = $curTime + (7-$curWeekday) *86400;

13

$cur [' Mon '] = $curMon;

$cur [' Sun '] = $curSun;

16

return $cur;

18}

$cur = Getmonsun ();

20

echo Date (' y-m-d ', $cur [' Mon ']);

echo "RN";

echo Date (' y-m-d ', $cur [' Sun ']);

?>


Method Three

?

The function Getmonsun () {

$curTime =time ();

04

05//Find out the current day of the week:

$curWeekday = Date (' W ');

07

08///If Monday is reduced to 7*86400 Tuesday minus 6*86400, and so on to get the Monday timestamp:

Switch ($curWeekday) {

Case 0:

One $curMon = $curTime -7*86400;

$curSun = $curTime;

break;

Case 1:

$curMon = $curTime;

$curSun = $curTime +6*86400;

break;

Case 2:

$curMon = $curTime -1*86400;

$curSun = $curTime +5*86400;

break;

Case 3:

$curMon = $curTime -2*86400;

$curSun = $curTime +4*86400;

break;

Case 4:

$curMon = $curTime -3*86400;

$curSun = $curTime +3*86400;

break;

Case 5:

$curMon = $curTime -4*86400;

$curSun = $curTime +2*86400;

The break;

Case 6:

$curMon = $curTime -5*86400;

$curSun = $curTime +1*86400;

The break of the Panax Notoginseng;

38}

$cur [' Mon '] = $curMon;

$cur [' Sun '] = $curSun;

41

return $cur;

43}

$cur = Getmonsun ();

The Echo date (' y-m-d ', $cur [' Mon ']);

The echo "RN";

The Echo date (' y-m-d ', $cur [' Sun ']);

?>

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.