Wednesday, November 12, 2008

How to get the Fourth Monday of Current Month

The following sql function will return the Fourth Monday of the Current Month.

CREATE FUNCTION [dbo].[GetFourthMondayOfCurrentMonth]
(

)
RETURNS DATETIME
BEGIN
declare @Today as datetime
declare @FirstMonday as datetime
declare @FourthMonday as datetime
set @Today = getdate()

select @FirstMonday = DATEADD(wk, DATEDIFF(wk,0,dateadd(dd,6-datepart(day,@Today),@Today)),0)

set @FourthMonday = DATEADD(day,21,@FirstMonday)

return @FourthMonday
END

0 comments: