PHP 获取两个日期之间所有日期
生活随笔
收集整理的這篇文章主要介紹了
PHP 获取两个日期之间所有日期
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
public function getDatesBetweenTwoDays($startDate,$endDate){$dates = [];if(strtotime($startDate)>strtotime($endDate)){//如果開始日期大于結(jié)束日期,直接return 防止下面的循環(huán)出現(xiàn)死循環(huán)return $dates;}elseif($startDate == $endDate){//開始日期與結(jié)束日期是同一天時array_push($dates,$startDate);return $dates;}else{array_push($dates,$startDate);$currentDate = $startDate;do{$nextDate = date('Y-m-d', strtotime($currentDate.' +1 days'));array_push($dates,$nextDate);$currentDate = $nextDate;}while($endDate != $currentDate);return $dates;}}
如果有幫到您,打個賞唄
總結(jié)
以上是生活随笔為你收集整理的PHP 获取两个日期之间所有日期的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MySql 查询小数保留两位小数
- 下一篇: 根据表中的时间戳字段统计每天数据的数量