Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Number of days between a given date & 3rd sunday of current month.

Total Hit ( 1438)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


This T-SQL script shows how to calculate the number of days between a given date and the 3rd sunday of the current month. This can be easily modified to accomodate count till 3rd saturday or 3rd monday of current month & so on.

Click here to copy the following block
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


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.