I have a database schema to create reminders very similar to Outlook. You can create Weekly, Monthly and Yearly reminders.
I need to be able to find something like:
The first Friday of January
The third Wednesday of every 3 months.
Can anyone tell me how to find something like the first, second, third, fourth, etc. date in SQL Server 2008?
Use
datepartto find out the day of week for the first day of the month:From that you can calculate the first of any weekday, for example the first Monday (2):
To get the second monday you just add 7 to that, and so on.
To check if the date is still within the same month you would need the last date of the month, which you can get by subtracting a day from the first day of the next month: