Tuesday, April 13, 2010

How to get the first day of the week in SQL Server

CREATE FUNCTION [dbo].[udf_GetFirstDayOfWeek](
@pInputDate DATETIME
)
RETURNS DATETIME
BEGIN

SET @pInputDate = CONVERT(VARCHAR(10), @pInputDate, 111)
RETURN DATEADD(DD, 1 - DATEPART(DW, @pInputDate),
@pInputDate)

END
GO

No comments: