PHP获取两个时间之间的所有日期
16lz
2021-08-18
实例
/***获取两个时间之间的日期*@param$startDate*@param$endDate*@returnarray*/publicfunctiongetDatesBetweenTwoDays($startDate,$endDate){$dates=[];if(strtotime($startDate)>strtotime($endDate)){//如果开始日期大于结束日期,直接return防止下面的循环出现死循环return$dates;}elseif($startDate==$endDate){//开始日期与结束日期是同一天时array_push($dates,$startDate);return$dates;}else{array_push($dates,$startDate);$currentDate=$startDate;do{$nextDate=date('Y-m-d',strtotime($currentDate.'+1days'));array_push($dates,$nextDate);$currentDate=$nextDate;}while($endDate!=$currentDate);return$dates;}}
运行实例 »
点击 "运行实例" 按钮查看在线实例
更多相关文章
- 补:0811作业 类与对象
- 作业内容:oop基础:请举例实例演绎以下难点 1. 类(对象抽象化的结
- Excel表格中,提取身份证的生日转为日期
- php面向对象的入门学习(类与对象)
- 1. 请实例演绎你对面向对象类与对象关系的理解? 2. 请实例演绎oop
- 类的属性、封装、构造函数
- php简单实现模拟用户登陆验证
- PHP数组处理初体验
- 回调函数与递归函数实例总结