1. The following functions can be used directly.
function Getreportdates ($periods) {
$dates = Array ();
Start and end time of the current time period
$end = Getweekendbydate ($periods);
$start = Date ("y-m-d", Strtotime ("-". $periods-1). "Day", Strtotime ($end)));
Get Date ($times cycles)
$dates [' start '] = $start. " 00:00:00 ";
$dates [' end '] = $end. " 23:59:59 ";
return $dates;
}
/**
* Get natural days, weeks, months
* @param date: Today's Day
* @return Array: Start time and end time.
*/
function Getweekendbydate ($periods) { //$periods is the number of days 1 7 30
$st = Array (1=> ' Day ',7=> ' Week ',30=> ' month ');
if (Array_key_exists ($periods, $st)) {
$type = $st [$periods];
}else{
$type = ";
}
Switch ($type) {
Case ' Week ':
$day = Date (' N ', Time ()); The current date is the day of the week
if ($day <2) {
Return date ("Y-m-d", Time ()-86400 * ($day +7));
}else {//Get last week's weekend date.
Return date ("Y-m-d", Time ()-86400 * $day);
}
Case ' Day ':
Return date ("Y-m-d", Time ()-86400 * 2); Returns the date of the day before
Case ' Month ':
if ((int) date ("D", Time ()) <2) {
Return date ("Y-m-d", Strtotime (Date ("y-m-0", Strtotime ("1 Month", Strtotime (Date ("Y-m", Time ())))));
}else{
Return date ("Y-m-d", Strtotime (Date ("y-m-0", Time ()));
}
Default
return date ("y-m-d", Strtotime ("1 days");//day before
}
}
Get Natural day-week time