PHP日期、時間戳記相關的小程式

來源:互聯網
上載者:User

標籤: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‘ )");

註:沒有的日期,顯示為空白。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.