SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 DATE ISSUE..PLZ SOLVE
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

raky
Aged Yak Warrior

767 Posts

Posted - 05/22/2008 :  10:18:52  Show Profile  Reply with Quote
hi,

I HAVE THE FOLLOWING DATA

DECLARE @D1 DATETIME,@D2 DATETIME
SELECT @D1 = '06/05/2005' ,@D2 = '05/22/2008'

I NEED TO GET THE DIFFERENCE BETWEEN TWO DATES

PLEASE DON'T CONSIDER ONLY YEAR PART

I.E., SELECT DATEDIFF(YEAR,@D1,@D2) IS NOT VALID IN MY CONTEXT

I need to consider the days and months also.

I need to determine whether the difference is greater than 3 years or not.

FOR THE ABOVE GIVEN DATA IT IS LESS THAN 3 YEARS
IN THIS CASE I NEED TO GET OUTPUT AS LESS THAN 3 YEARS

I ALWAYS ASSIGN @D2 WITH GETDATE().

PLEASE HELP ME...

THANKS IN ADVANCE...

RickD
Slow But Sure Yak Herding Master

United Kingdom
3608 Posts

Posted - 05/22/2008 :  10:20:04  Show Profile  Reply with Quote
So change it to days to find out how many days there are different.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30106 Posts

Posted - 05/22/2008 :  10:26:30  Show Profile  Visit SwePeso's Homepage  Reply with Quote
See http://www.sqlteam.com/article/datediff-function-demystified



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

jsmith8858
Dr. Cross Join

USA
7423 Posts

Posted - 05/22/2008 :  10:45:17  Show Profile  Visit jsmith8858's Homepage  Reply with Quote
Also, see:

http://www.sqlteam.com/article/working-with-time-spans-and-durations-in-sql-server

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

USA
7020 Posts

Posted - 05/22/2008 :  10:59:50  Show Profile  Reply with Quote
The function on this link, F_AGE_IN_YEARS, will give the difference in years.
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=74462



CODO ERGO SUM
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000