php獲取開始與結束日期之間所有日期的方法
本文實例講述了php獲取開始與結束日期之間所有日期的方法。分享給大家供大家參考,具體如下:
/**
* 獲取指定日期段內(nèi)每一天的日期
* @param Date $startdate 開始日期
* @param Date $enddate 結束日期
* @return Array
*/
function getDateFromRange($startdate, $enddate){
$stimestamp = strtotime($startdate);
$etimestamp = strtotime($enddate);
// 計算日期段內(nèi)有多少天
$days = ($etimestamp-$stimestamp)/86400+1;
// 保存每天日期
$date = array();
for($i=0; $i<$days; $i++){
$date[] = date('Y-m-d', $stimestamp+(86400*$i));
}
return $date;
}
$startdate = '2016-08-29';
$enddate = '2016-09-29';
// demo
$date = getDateFromRange($startdate,$enddate);
print_r($date);
運行結果如下:
Array ( [0] => 2016-08-29 [1] => 2016-08-30 [2] => 2016-08-31 [3] => 2016-09-01 [4] => 2016-09-02 [5] => 2016-09-03 [6] => 2016-09-04 [7] => 2016-09-05 [8] => 2016-09-06 [9] => 2016-09-07 [10] => 2016-09-08 [11] => 2016-09-09 [12] => 2016-09-10 [13] => 2016-09-11 [14] => 2016-09-12 [15] => 2016-09-13 [16] => 2016-09-14 [17] => 2016-09-15 [18] => 2016-09-16 [19] => 2016-09-17 [20] => 2016-09-18 [21] => 2016-09-19 [22] => 2016-09-20 [23] => 2016-09-21 [24] => 2016-09-22 [25] => 2016-09-23 [26] => 2016-09-24 [27] => 2016-09-25 [28] => 2016-09-26 [29] => 2016-09-27 [30] => 2016-09-28 [31] => 2016-09-29 )
更多關于PHP相關內(nèi)容感興趣的讀者可查看本站專題:《php日期與時間用法總結》、《PHP數(shù)組(Array)操作技巧大全》、《PHP基本語法入門教程》、《PHP運算與運算符用法總結》、《php面向對象程序設計入門教程》、《PHP網(wǎng)絡編程技巧總結》、《php字符串(string)用法總結》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設計有所幫助。
相關文章
PHP實現(xiàn)將多個文件中的內(nèi)容合并為新文件的方法示例
這篇文章主要介紹了PHP實現(xiàn)將多個文件中的內(nèi)容合并為新文件的方法,涉及php編碼轉換、文件與目錄的遍歷以及文件讀寫相關操作技巧,需要的朋友可以參考下2017-06-06
php函數(shù)array_merge用法一例(合并同類數(shù)組)
合并同類型數(shù)組,array_merge ()函數(shù)的簡單例子,供大家參考2013-02-02
php獲取mysql數(shù)據(jù)庫中的所有表名的代碼
如何用PHP獲取MYSQL數(shù)據(jù)庫的所有表名?記得在mysql命令行下面有條命令SHOW TABLES是顯示mysql數(shù)據(jù)庫里面所有數(shù)據(jù)表的,那么就用這條命令來遍歷數(shù)據(jù)表名吧2011-04-04
PHP基于curl模擬post提交json數(shù)據(jù)示例
這篇文章主要介紹了PHP基于curl模擬post提交json數(shù)據(jù)操作,結合實例形式分析了php使用curl實現(xiàn)post方式提交json數(shù)據(jù)相關操作步驟與注意事項,代碼簡單實用,需要的朋友可以參考下2018-06-06
php+mysql實現(xiàn)的二級聯(lián)動菜單效果詳解
這篇文章主要介紹了php+mysql實現(xiàn)的二級聯(lián)動菜單效果,涉及php操作mysql的連接、查詢結合javascript的DOM節(jié)點操作實現(xiàn)二級聯(lián)動菜單效果,末尾還附帶了mysql數(shù)據(jù)庫相應的sql語句,需要的朋友可以參考下2016-05-05

