I need a bit of help using symfony to calculate an end date. The user will select a start date, a frequency (Ex. Every 7 Days, Every 14 Days, Every Month, Semi-Annually – Every 6 Months, etc), and the number of occurrences.
Examples:
Start date: 08/01/2010
Frequency: Every 7 days
Occurrences: 4
End Date = 08/29/2010
Start date: 08/01/2010
Frequency: Every Month
Occurrences: 3
End Date = 11/01/2010
Some notes- Our server is running PHP 5.2.13 and Symfony 1.1. It’s not a requirement that I use symfony to adjust the date, as long as I can get it back to a format that symfony can validate.
Thanks in advance.
You can use a
strtotimefor this, e.g.gives
2010-09-06.Of course, you will have to multiply “+1 month” for the number of occurrences, so that it becomes e.g. “+7 months” for 7 occurrences.
Alternatively (more simple but less efficient), you can use a fixed interval (e.g. “+1 month”) and use a
forloop: