Uri Dimant
3/28/2007 6:13:00 AM
John
This UDF written by Steve Kass, it will give you some ideas
create function dbo.NthWeekDay(
@first datetime, ---'20070301
@nth tinyint, -- Which of them - 1st, 2nd, etc.
@dow tinyint -- Day of week we want
) returns datetime as begin
-- Note: Returns a date in a later month if @nth is too large
declare @result datetime
set @result = @first + 7*(@nth-1)
return @result + (7 + @dow - datepart(weekday,@result))%7
end
select dbo.NthWeekDay ('20070318',1,1),dbo.NthWeekDay ('20070318',1,7)
"John Grandy" <johnagrandy-at-gmail-dot-com> wrote in message
news:ubDntIMcHHA.984@TK2MSFTNGP04.phx.gbl...
>I need to calculate a datetime for the start of the current week (Sunday
>12:00:00AM) and a datetime for the end of the current week (Saturday
>11:59:59 PM).
>
> I've written some long-winded code to do this involving building up
> strings and then explicitly or implicitly casting them to datetime.
>
> But is there a better way ?
>