I’m trying to reschedule recurring events based on the recurring method: daily, weekly or monthly.
So assuming I have this data:
$now = time();
$start_date = '01/01/2011 14:00';
$end_date = '01/01/2011 14:20';
$start_time = date('H:i', $start_date);
$end_time = date('H:i', $end_date);
$period = $end_date - $start_date; // in this case, 20 minutes
This event rescheduled daily would be:
$new_time_start = strtotime(date("m/d/Y {$start_time}", $now));
$new_time_end = $new_time_start + $period;
And monthly:
$start_day = date('d', $start_date);
$new_time_start = strtotime(date("m/{$start_day}/Y {$start_time}", $now));
$new_time_end = $new_time_start + $period;
It seems to be working, but I don’t know how to do the same for weekly events 🙁
For example ’01/01/2011′ is Saturday, so I want to reschedule the event to run every Saturday (day 6 of the week according to PHP).
Any ideas?
Give this a try…
It seems as though you’re missing some strtotime( ) wrappers around your $start_date and $end_date values. I’m assuming your storing your start and end date variables as unix timestamps, so I didn’t include them in my code either.
Also, just as a side note, you don’t have to enter time( ) in date( ) as the second argument. If the time value is missing, it will use the current time. So you can remove all your $now instances and it will still work.