I’ve been asked for an T-SQL challenge, I need to get the equivalent day on next month based on day position like this:
Today is 18/07/2011 in other words is the third Monday of this month…
Now I need to get the third Monday of next month (15/08/2011) on a SQL Server query.
This is like google calendar’s recurrence rules.
I’ve been trying a lot of formulas but it gets very complicated, any help would be really appreciated.
this may help someone, if you want to get the ordinal date any number of months from now, I’ve created this function as a combination of all of your advices:
it receives date and number of months, gets the ordinal number of the day and the first day of the month you want. With this last one finds the first occurrence of the week day in that month, then it calculates corresponding ordinal date any months from your date.
I know it has a lot of code and might be improved but at least it works pretty well.