PHP query within a specified time range all day, month, quarter, year

 

/ * * 
 * Query all dates within the specified time frame, month, quarter, year 
 * 
 * @param $ startDate specify the start time, Ymd format 
 * @param $ endDate specify an end time, Ymd format 
 * @param $ type type, day day , month month, quarter quarter, year year 
 * @return Array 
 * / 
function getDateByInterval ( $ startDate , $ endDate , $ of the type ) 
{ 
    IF ( DATE ( 'Ym-d', strtotime ( $ startDate ))! = $ startDate || DATE ( 'Ym of-D', strtotime ( $ endDate ))! = $ endDate ) {
         return'Date format is incorrect' ; 
    } 
 
    $ tempDate = $ startDate ;
     $ returndata = [];
     $ I = 0 ;
     IF ( $ type == 'Day') {     // Search date of 
        the while ( strtotime ( $ tempDate ) < strtotime ( $ endDate )) {
             $ tempDate = DATE ( 'Ym of-D', strtotime ( '+'. $ I 'Day',. strtotime ( $ startDate )));
             $ returndata [] =tempDate $ ;
             $ I ++ ; 
        } 
    } ELSEIF ( $ type == 'month The') {     // Search start and end time of the month 
        the while ( strtotime ( $ tempDate ) < strtotime ( $ endDate {))
             $ TEMP = [] ;
             $ month The = strtotime ( '+'. $ I 'month The',. strtotime ( $ startDate ));
             $ TEMP [ 'name'] = DATE ( 'the Y-m', $ month The );
            $ TEMP [ 'startDate'] = DATE ( 'Ym of-01', $ month The );
             $ TEMP [ 'endDate'] = DATE ( 'Ym of-T', $ month The );
             $ tempDate = $ TEMP [ 'endDate' ] ;
             $ returndata [] = $ TEMP ;
             $ I ++ ; 
        } 
    } ELSEIF ( $ type == 'quarter') {     // Search quarter start and end time of 
        the while ( strtotime ( $ tempDate ) < strtotime ( $ endDate)) {
            $temp = [];
            $quarter = strtotime('+' . $i . ' month', strtotime($startDate));
            $q = ceil(date('n', $quarter) / 3);
            $temp['name'] = date('Y', $quarter) . '第' . $q . '季度';
            $temp['startDate'] = date('Y-m-01', mktime(0, 0, 0, $q * 3 - 3 + 1, 1, date( 'The Y', $ Quarter )));
             $ TEMP [ 'endDate'] = DATE ( 'Ym of-T', the mktime (23 is, 59, 59, $ Q *. 3,. 1, DATE ( 'the Y', $ Quarter )));
             $ tempDate = $ TEMP [ 'endDate' ];
             $ returndata [] = $ TEMP ;
             $ I = $ I +. 3 ; 
        } 
    } ELSEIF ( $ type == 'year') {     // query all years and start time end 
        the while ( strtotime ( $ tempDate) < strtotime($endDate)) {
            $temp = [];
            $year = strtotime('+' . $i . ' year', strtotime($startDate));
            $temp['name'] = date('Y', $year) . '年';
            $temp['startDate'] = date('Y-01-01', $year);
            $temp['endDate'] = date('Y-12-31', $year);
            $ temp=$ tempDate['endDate'];
            $returnData[] = $temp;
            $i++;
        }
    }
    return $returnData;
}

 

Guess you like

Origin www.cnblogs.com/woods1815/p/10958642.html