PHP gets the start date and end date (implementation code) of the Week (month) where the current date is located _php tips

Source: Internet
Author: User
Nonsense not much, on the code
Copy Code code as follows:

Gets the start and end times of the week on which the specified date is located
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;
}

Gets the start date and end date of the month on which 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;
}


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://one weeks.
$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;
}

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.