Hi,
This is a nice idea, however, with the implementation I see an issue. What if I want to find the first Tuesday for july 2009? Instead of -8 I would have to do -4 and this lands me in June 30th 2009!?
Jack/Alphonse--I understand that your initial implementation was to get the first Saturday
Here is a slightly modified version which relies on the default datefirst which is 7
declare @DW int
set @DW = 2 -- [Sunday - Saturday] == [1 - 7]
declare @d datetime
set @d = '7/21/2009'
declare @first datetime
set @first = convert(varchar, datepart(mm, @d)) + '/01/' + convert(varchar,datepart(yyyy, @d))
declare @dayofweek int
set @dayofweek = DATEPART(dw,@first)
print @first + (7+(@dw - @dayofweek))%7