First of, you might consider this question also helpful: http://stackoverflow.com/questions/1579638/what-is-the-best-way-to-represent-recurring-events-in-database
Brenton Alker-3 wrote: > >> If the timespans are really complex, in essence: can not be catched in a >> limited amount of time values, you will always need to have an algorithm > > >> In your logic, be it php or a self written mysql function for example, >> you >> would get the actual value based on the interval constant. > > That would require essentially hard coded all possible date allocations, > which isn't very flexible. > This suggestion really is against literally enumerating all possible dates. The algorithm generates the desired span of dates. >> Simple things like "next saturday", "+1 month" are understood by php date >> functions (http://php.net/manual/en/function.strtotime.php) >> >> $d = new DateTime('next saturday'); >> echo $d->format('d, F Y'); //works! > > True, but I'm not sure that's too helpful in this case. > It depends on what you want. If you want to list all future dates of a specif event, it would be enough to store a date representation that you could hand directly over to strtotime/DateTime/... > This is essentially what I am doing now, basically modeled after crontab > as I originally mentioned. I've only got a column for day, month and > weekday so far, but it is easy to add additional columns at a later date > as requirements become more complex. > > Finding the next date is currently a matter of looping through the days > and seeing if they match all criteria (limited to checking one year > ahead to prevent an infinite loop). That part can probably be refactored > later, but it works for now. > That's a pain indeed. I think this can be optimized. Maybe you should also look at the possibility to generate and store all matchting dates in the databases, making it easier to perform difficult selects. -- View this message in context: http://www.nabble.com/Finding-%22next%22-date-for-an-event-tp25993104p26056694.html Sent from the Zend Framework mailing list archive at Nabble.com.
