PHP从星期获取日期

时间:2012-09-03 05:55:25

标签: php date

如何使用for循环(7天)获取特定周的日期

例如,

$date_start = '2012/09/03';

我想获得功能日期即。 '2012/09/04','2012/09/05','2012/09/06'...'2012/09/08'一周。

我收到了代码,但执行时间很长:

while(strtotime($ start_date)< = strtotime($ end_date)){}

2 个答案:

答案 0 :(得分:1)

这是你可以做的解决方案,如

$date_start = '2012/09/03';

$end_date = date ("Y/m/d", strtotime("+7 day", strtotime($date_start)));

while (strtotime($date_start) <= strtotime($end_date)) {
        echo $date_start = date ("Y/m/d", strtotime("+1 day", strtotime($date_start)));         

    }

这是实时工作示例

Demo

或者只是访问链接..希望它有所帮助

php future Date in loop

答案 1 :(得分:-1)

$date = '2012/09/03'; // Start date
$date_seconds = strtodste($date); // Unix-time format (in seconds from 01.01.1970)
$week_seconds = 3600 * 24 * 7; // Second in week = 604800

while(true){

    $date_seconds += $week_seconds;

    var_dump(date('Y/d/m', $date_seconds));

}
相关问题