我有一个过去的约会日期。 每个新约会与前一个约会相隔8天(过去约会+ 8天)。 我想创建一个简单的脚本,以便每次从当天开始返回接下来365天的约会日期(即0 =< interval(today-appointment)=< 365)。
我尝试过这样的事情,但我得不到我想要的东西:
<?php
date_default_timezone_set('Europe/London');
$today = new DateTime("now");
$appointment=new DateTime('2013-08-26');
$interval = $appointment->diff($today)->d;
while ($interval <= 365 && $interval => 0)
{
echo $appointment->format('l n F Y');
$appointment->add(new DateInterval('P8D'));
} ?>
答案 0 :(得分:0)
你的问题总结:
+8 day interval
从过去的约会开始; +8 days
; today
和today+365days
间隔; date_default_timezone_set('Europe/London');
$today = new DateTime('today');
$appointment = new DateTime('2013-08-23');
$next_appointment_in_days = ceil($appointment->diff($today)->days / 8) * 8;
$next_appointment = clone $appointment;
$next_appointment->modify("+$next_appointment_in_days day");
do {
echo $next_appointment->format('l, j F Y') . "\n";
$next_appointment->modify('+8 day');
} while ($today->diff($next_appointment)->days <= 365);