In MySQL, I can do something like:
SELECT DATE_ADD(‘2010-07-02’, INTERVAL 1 MONTH)
And that returns:
2010-08-02
That’s great… now is there a MySQL function that I can use to find what the date would be one month in advance on the same day. For example, 7/2/2010 falls on the first Friday of July, 2010. Is there an easy way to find what the first Friday of August, 2010 is with an SQL statement?
It got a bit complicated, but here goes:
Rationale: If you add 4 weeks or 5 weeks, you’re still on the same day; since all months are between 28 and 35 days long, if 4 weeks later is still the same month, add another week.
UPDATE: Umm, I did not think this through very well – it works for first X in month, but necessarily for 2nd, 3rd… (i.e. 3rd X in month might return a 2nd X next month). Try #2:
Rationale:
CEIL(DAY(x) / 7)is x’s week number. If it’s different when you add 5 weeks, then add 4 weeks.UPDATE 2: LOL, I suck today, I should really think before I post… Week is usually defined as Mon-Sun, or Sun-Mon, not as from whatever started the month till 6 days later. To compensate for this: