PHP:从日期开始接下来的13个日期? [英] PHP: get next 13 dates from date?
问题描述
我正在尝试获得一个日期数组加上下一个13个日期,以便从给定的日期开始获得14天的时间表。
I am trying to get an array of a date plus the next 13 dates to get a 14 day schedule starting from a given date.
这是我的功能:
$time = strtotime($s_row['schedule_start_date']); // 20091030
$day = 60*60*24;
for($i = 0; $i<14; $i++)
{
$the_time = $time+($day*$i);
$date = date('Y-m-d',$the_time);
array_push($dates,$date);
}
但是似乎重复一个日期,当月切换..
But it seems to be repeating a date when the month switches over..
这是我得到的:
2009-10-30 | 2009- 10-31 | 2009-11-01 | 2009-11-01 | 2009-11-02 | 2009-11-03 | 2009-11-04 | 2009-11-05 | 2009-11-06 | 2009-11- 07 | 2009-11-08 | 2009-11-09 | 2009-11-10 | 2009-11-11
2009-10-30|2009-10-31|2009-11-01|2009-11-01|2009-11-02|2009-11-03|2009-11-04|2009-11-05|2009-11-06|2009-11-07|2009-11-08|2009-11-09|2009-11-10|2009-11-11
请注意2009-11-01重复。我不知道为什么?
Notice that 2009-11-01 is repeated. I cannot figure out why?
我做错了什么?
谢谢!!
推荐答案
我将使用strtotime
I would use strtotime
$start = strtotime($s_row['schedule_start_date']);
$dates=array();
for($i = 1; $i<=14; $i++)
{
array_push($dates,date('Y-m-d', strtotime("+$i day", $start)));
}
print_r($dates);
这篇关于PHP:从日期开始接下来的13个日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!