if($filter[' Mode ']) { Switch($filter[' Mode ']) { Case1://today's Data $time _start=Date("Y-m-d h:i:s",Mktime(0, 0, 0,Date(' m '),Date(' d '),Date("Y"))); $time _end=Date("Y-m-d h:i:s",Mktime(23,59,59,Date(' m '),Date(' d '),Date("Y"))); $ex _where. = ' and dt >= '.Strtotime($time _start) . ' and DT <= '.Strtotime($time _end); Break; Case2://yesterday's data $time _start=Date("Y-m-d h:i:s",Mktime(0, 0, 0,Date(' m '),Date(' d '),Date("Y"))); $time _end=Date("Y-m-d h:i:s",Mktime(23,59,59,Date(' m '),Date(' d '),Date("Y"))); $ex _where. = ' and dt >= '.Strtotime($time _start) . ' and DT <= '.Strtotime($time _end); Break; Case3://this week's data $time _start=Date("Y-m-d h:i:s",Mktime(0, 0, 0,Date("M"),Date("D")-Date("W") +1,Date("Y"))); $time _end=Date("Y-m-d h:i:s",Mktime(23,59,59,Date("M"),Date("D")-Date("W") +7,Date("Y"))); $ex _where. = ' and dt >= '.Strtotime($time _start) . ' and DT <= '.Strtotime($time _end); Break; Case4://last week's data $time _start=Date("Y-m-d h:i:s",Mktime(0, 0, 0,Date("M"),Date("D")-Date("W") +6,Date("Y"))); $time _end=Date("Y-m-d h:i:s",Mktime(23,59,59,Date("M"),Date("D")-Date("W"),Date("Y"))); $ex _where. = ' and dt >= '.Strtotime($time _start) . ' and DT <= '.Strtotime($time _end); Break; Case5://data for the current month $time _start=Date("Y-m-d h:i:s",Mktime(0, 0, 0,Date("M"), 1,Date("Y"))); $time _end=Date("Y-m-d h:i:s",Mktime(23,59,59,Date("M"),Date("T"),Date("Y"))); $ex _where. = ' and dt >= '.Strtotime($time _start) . ' and DT <= '.Strtotime($time _end); Break; Case6://last month's data $time _start=Date("Y-m-d h:i:s",Mktime(0, 0, 0,Date("M") -1,1,Date("Y"))); $time _end=Date("Y-m-d h:i:s",Mktime(23,59,59,Date("M"), 0,Date("Y"))); $ex _where. = ' and dt >= '.Strtotime($time _start) . ' and DT <= '.Strtotime($time _end); Break; Case7://this season's data $season=Ceil((Date(' n ')) /3);//The first quarter of the month $time _start=Date(' Y-m-d h:i:s ',Mktime(0, 0, 0,$season*3-3+1,1,Date(' Y '))); $time _end=Date(' Y-m-d h:i:s ',Mktime(23,59,59,$season,Date(' t ',Mktime(0, 0, 0,$season*3,1,Date("Y"))),Date(' Y '))); $ex _where. = ' and dt >= '.Strtotime($time _start) . ' and DT <= '.Strtotime($time _end); Break; Case8://last season's data $season=Ceil((Date(' n ')) /3)-1;//The first quarter of the month $time _start=Date(' Y-m-d h:i:s ',Mktime(0, 0, 0,$season*3-3+1,1,Date(' Y '))); $time _end=Date(' Y-m-d h:i:s ',Mktime(23,59,59,$season,Date(' t ',Mktime(0, 0, 0,$season*3,1,Date("Y"))),Date(' Y '))); $ex _where. = ' and dt >= '.Strtotime($time _start) . ' and DT <= '.Strtotime($time _end); Break; Case9://this year's data $time _start=Date("Y-m-d h:i:s",Mktime(0, 0, 0,1,1,Date("Y"))); $time _end=Date("Y-m-d h:i:s",Mktime(23,59,59,12,Date(' t '),Date("Y"))); $ex _where. = ' and dt >= '.Strtotime($time _start) . ' and DT <= '.Strtotime($time _end); Break; Case10://last year's data $time _start=Date("Y-m-d h:i:s",Mktime(0, 0, 0,1,1,Date("Y")-1)); $time _end=Date("Y-m-d h:i:s",Mktime(23,59,59,12,Date(' t '),Date("Y")-1)); $ex _where. = ' and dt >= '.Strtotime($time _start) . ' and DT <= '.Strtotime($time _end); Break; default://All Break; } }
PHP printing Today, yesterday, this week, last week, month, month, this season, last quarter, this year, last year data