Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 DATE ISSUE..PLZ SOLVE

Author  Topic 

raky
Aged Yak Warrior

767 Posts

Posted - 2008-05-22 : 10:18:52
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

3608 Posts

Posted - 2008-05-22 : 10:20:04
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

30421 Posts

Posted - 2008-05-22 : 10:26:30
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

7423 Posts

Posted - 2008-05-22 : 10:45:17
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)

7020 Posts

Posted - 2008-05-22 : 10:59:50
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
   

- Advertisement -