DECLARE @StartDate datetime , @EndDate datetime
SELECT @StartDate = '2/13/2000' ,
-- Calculate 1st day of the month
@EndDate = CAST( CAST( YEAR( GETDATE() ) AS varchar ) +
RIGHT( '00' + CAST( MONTH( GETDATE() ) AS varchar ) , 2 ) + '01'
as datetime )
-- Determine 1st sunday of the month ( 7 - DATEPART...) expression
-- Add 14 days to get the 3rd sunday & do DATEDIFF
SELECT DATEDIFF( dd , @StartDate ,
DATEADD( dd , 14 + ( 7 - DATEPART( dw, @EndDate ) ) , @EndDate ) ) AS #Days
This page was last updated on May 01, 2006 04:28 PM.