Yes raj had that in his php code example. I started with that but was missing something, I had to break it down a little further to understand and debug. I’ll check out that class. Date calculations are sometimes hard for me to get my head around, but their understanding is essential.
I agree with felgall, salathe’s solution is cleanest. I have not yet utilized views in MySQL but will start reading about them.
The select statement Salathe supplied is probably the simplest way to do this as it simply returns the exact date you are looking for from the database call in the first place so that it is as if that date were stored in the database from the start.
The only way of making it any simpler than that would be to set up a view on the table that includes that result as a field that can be directly accessed by name as if the next occurrence date were stored in the database.
echo date('Y m d' , strtotime( '2010-08-12 + 7 days') );
It might not be applicable in your case because I don’t know enough about it - but if the periods are days then this is a lot more comfortable to work with, and easier to read when you come back later, thats all I want to point out.
The datetime class I mentioned earlier builds upon the strtotime() function too.
Guido I think your math is closer to what I am looking to do.
Rajug, that would give me the next occurrence date from the start date. These events happen indefinitely and I am looking for the next date it will occur in the future.
I have a MySQL table containing a start date of type date, and an occurrence interval of type int representing the number of days between occurrences. I am looking for the next future occurrence for each row.. So the start date might be 2009-12-15 and the occurrence interval 45, when is the next occurrence in the future?
You could use the MySQL functions to calculate the difference in days between today and the start date, and divide that number by the number of days between occurrences, and if the rest of that division is 0, it’s a match
Yes, I am aware of the various date functions available in MySQL and PHP. I was hoping for some help in regards to how you would use the functions to do the necessary calculations in either MySQL or PHP. I am thinking MySQL might be the most optimal, but I leave that up to you.
I am converting the amount of time to a unix timestamp (expressed in seconds) before adding it to the recurring start date unix timestamp. There are other simpler ways to do this mentioned earlier in the thread… I just happened to end up with this through my debugging process.