March 15, 2008 at 5:23 am
Hi,
I have a situation where I need to determine the date of the second saturday of March of a year. How to do that?
For example, for 2008, it should give 9 (as the second sunday of March this is is 9th). For 2009 it should give 8 (as the second sunday of March next year would be the 8th of March), for 2010 it should give 14 (as the second sunday of March in year 2010 is the 14th of March) etc.
Thanks in advance
RS
March 15, 2008 at 9:45 am
One way you could do it something like this:
With DayOfWeek As
(
Select
DateName(DW, date) as DayOfWeek,
date
From
dates
Where
date between '2008/03/08' and '2008/03/14'
)
Select
date
From
DayOfWeek
Where
DayofWeek = 'Saturday'
or
With DayOfWeek As
(
Select
DateName(DW, date) as DayOfWeek,
date,
DatePart(DD, date) as DayNum,
DatePart(mm, date) as MonthNum,
From
dates
)
Select
date as DateOfSecondSaturday
From
DayOfWeek
Where
DayofWeek = 'Saturday' And
DayNum between 8 and 14 And
MonthNum = 3
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
March 15, 2008 at 10:47 am
Ummm... just in case you don't have a "Dates" table like what Jack used, please consider the information at the following URL...
--Jeff Moden
Change is inevitable... Change for the better is not.
March 15, 2008 at 12:41 pm
Actually Jeff, I did not mean to imply that there was a dates table. The OP did not post any table or column names so I just used dates as a generic name. Now a dates table might be the best solution for this.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
March 15, 2008 at 12:56 pm
Oh... ok. Thanks Jack.
Hey, do you have a dates table? I've got a neat trick to show you if you do...
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply