View Thread
 Print Thread
Get Week End Date (Sunday) of any date regardless of DATEFIRST
admin
Simple function to Get week end Date (Sunday) of any date regardless of DATEFIRST


CREATE FUNCTION [dbo].[udf_WeekEndDate] ( @Date DATETIME )
RETURNS DATETIME
AS
    BEGIN
        RETURN DATEADD(DAY, 7, CONVERT(DATETIME, CONVERT(VARCHAR(10), DATEADD(day, -1 - ( DATEPART(dw, @Date) + @@DATEFIRST - 2 ) % 7, @Date), 103) + ' 23:59:59', 103))
    END
GO

Edited by admin on 25-10-2011 14:05
Jordon Pilling | Heavencore Administrator
 
Jump to Forum