troubleshooting Question

I want to add a repeating event for a period defined by a start date and an ending date. How?

Avatar of Bruce Gust
Bruce GustFlag for United States of America asked on
PHP
7 Comments3 Solutions489 ViewsLast Modified:
So I've got this much figured out:

Say my user has a calendar event that they want to schedule to occur every two weeks for the next two months. To figure out the first date after their initial start date, I've got this:

$date = date_create('2013-07-16');
date_add($date, date_interval_create_from_date_string('14 days'));
echo date_format($date, 'Y-m-d'); //the next date in the sequence

I've yet to create a loop that would insert the data, but I'm stuck as far as how I would create a script that first calculates the number of times I would loop through the data.

For example, I'm looking at this:

// Show event dates for next 2 years
// one year = ~52 weeks
// 52 weeks / 4 weeks intervals = 13 months ;)
// So, two years = 26 intervals with 4 weeks
//
for($i = 1; $i <= 26; $i++)
{
    $weekOffset = $i * 4;
    $nextDate = strtotime("{$startDate} +{$weekOffset} weeks");
    echo date('Y-m-d l', $nextDate) . PHP_EOL.'<BR>';
}

But how do I do the computations that produce the $i variable based on the dates my user inputs as the start and end dates?

Thoughts?
ASKER CERTIFIED SOLUTION
zappafan2k2

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros