標籤:style blog color io 資料 2014 ar cti
1、日期區間內的日期列表(天):
1 public function dateExtent($begin,$end){2 $begin = strtotime($begin);3 $end = strtotime($end);4 while($begin<=$end){5 $dateArr[] = date(‘Y-m-d‘,$begin);6 $begin += 86400; 7 }8 return $dateArr;9 }
注釋:
$begin = ‘2014-07-29‘;
$end = ‘2014-08-05‘;
返回:Array ( [0] => 2014-07-29 [1] => 2014-07-30 [2] => 2014-07-31 [3] => 2014-08-01 [4] => 2014-08-02 [5] => 2014-08-03 [6] => 2014-08-04 [7] => 2014-08-05 )
2、日期區間內的月份列表(月):
1 public function monthExtent($begin,$end){ 2 $begin = strtotime($begin); 3 $end = strtotime($end); 4 $begin = date(‘Y-m‘,$begin); 5 $end = date(‘Y-m‘,$end); 6 $begin = strtotime($begin.‘-01‘); 7 $end = strtotime($end.‘-01‘); 8 while($begin<=$end){ 9 $monthArr[] = date(‘Y-m‘,$begin);10 $begin += strtotime(‘+1 month‘,$begin)-$begin;11 }12 return $monthArr;13 }
注釋:
$begin = ‘2013-10-07‘;
$end = ‘2014-02-05‘;
返回:Array ( [0] => 2013-10 [1] => 2013-11 [2] => 2013-12 [3] => 2014-01 [4] => 2014-02 )
3、指定日期的起始時間戳記和結束時間戳記:
1 $Tbegin = strtotime($date.‘ 00:00:00‘);2 $Tend = strtotime($date.‘ 23:59:59‘);
4、指定月份的起始時間戳記和結束時間戳記:
1 $Mbegin = strtotime($month.‘-01 00:00:00‘);2 $Mend = strtotime(date(‘Y-m-d‘,strtotime($month.‘-01 +1 month -1 day‘)).‘ 23:59:59‘);
另附:
資料庫儲存日期格式為時間戳記;
PHP 統計查詢每天的數量:
$Model->query("SELECT count( distinct did ) AS num, from_unixtime( `datetime` , ‘%Y-%m-%d‘ )AS time FROM `dealer_sell` WHERE uid=".$uid." and `datetime`>=".$begin." and `datetime` <=".$end." GROUP BY from_unixtime( `datetime` , ‘%Y%m%d‘ )");
註:沒有的日期,顯示為空白。