I have a past date of appointment set. Every new appointment is 8 days apart from the previous (past appointment+8 days). I would like to create a simple script to return the dates of appointments for the next 365 days starting from the current day each time (i.e. 0=< interval (today-appointment) =< 365).
I've tried something like this but I don't get what I want:
<?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'));
} ?>
Sum from your question :
+8 day interval
from appointment in the past;+8 days
from previous one;today
and today+365days
interval;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') . "
";
$next_appointment->modify('+8 day');
} while ($today->diff($next_appointment)->days <= 365);