Blog Home 
Scott Yokiel MOSS 2007 & .NET blog (and some bad spelling) - SQL begin of week

RSS 2.0 Atom 1.0 CDF  
 
Sign In
 
 Wednesday, April 09, 2008

Simple function to get the first day of the week.  It seems to perform nicly also.

ALTER FUNCTION [dbo].[F_Get_Sunday] (@MidWeekDate DateTime)

RETURNS DateTime AS

BEGIN

DECLARE @WeekCommence DateTime

SET @WeekCommence = DateAdd(d, -((@@DATEFIRST + DatePart(dw, @MidWeekDate) -1) % 7), @MidWeekDate)

RETURN CAST(FLOOR( CAST(@WeekCommence as FLOAT)) AS DATETIME)

END

4/9/2008 7:31:22 PM (Central Standard Time, UTC-06:00)  #    Comments [0]    |  Trackback
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Copyright © 2008 RBA Consulting.