Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare dates minus 2 months

Status
Not open for further replies.

Chuck712

Technical User
Mar 1, 2002
133
US
I am very new to SQL. I have a situation that calls for me to calculate renewing memberships. The criteria is that the membership join date must be greater than 2 months from the pay date. This is considered a renewal. Once I am able to get the correct results, I will need to make this available on an ongoing basis, so I don't want any hard coded dates.
I admit I am over my head on this one.
 
Define 2 months?
both of these with the same dates will return 32 days but 2 months, is this 2 months?

Code:
--2 months
declare @d datetime
select @d ='2005-12-31 00:00:00.000'
declare @d2 datetime
select @d2 ='2006-02-01 00:00:00.000'
select  datediff(m,@d,@d2)

--32 days
declare @d datetime
select @d ='2005-12-31 00:00:00.000'
declare @d2 datetime
select @d2 ='2006-02-01 00:00:00.000'
select  datediff(dd,@d,@d2)

Denis The SQL Menace
SQL blog:
Personal Blog:
 
Thank you. 60 days would be the more accurate way to compute this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top