Reverse question is - How to determine if the date is in last week of month?
For example, using GetDate() how would I know that today's date or given date is in last week of the month. As week number in MSSQL can be 4 or 5.
Suppose I want to get date of last Saturday of every month. But in SQL week number 5 (which is last week of Dec 2013) for Dec 2013 don't have Friday. Last week of December ends with Tue on 31st. So, I need to skip Dec and go further for January 2014 but there also last week ends on Friday 31st. So, keep moving....
So, how to get date of last week's X day from given date or today's date?
Thanks.
You can use the code below. It is based on week starting on Monday and ending on Sunday: