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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 diff between two dates

Author  Topic 

cognos79
Posting Yak Master

241 Posts

Posted - 2008-09-30 : 13:16:19
Is there a user defined function that returns the difference between two dates descriptively:

St date: 01/01/2008
end date: 09/15/2008 as

0 years, 8 months, 15 days...

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-09-30 : 13:28:19
If by "defined" you mean a built in sql function, then no. You would have to write your own or find for one that someone else has already written.

Be One with the Optimizer
TG
Go to Top of Page

cognos79
Posting Yak Master

241 Posts

Posted - 2008-09-30 : 13:31:23
I am trying to find if anybody has already written a function that does it...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-30 : 13:42:08
only upto days or even time difference upto seconds?
Go to Top of Page

cognos79
Posting Yak Master

241 Posts

Posted - 2008-09-30 : 13:42:39
just until days...
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-09-30 : 14:41:23
This can be tricky...I think you'll need to define some reqirements.

Given these dates should you get the same result?
St date: 01/12/2008
end date: 09/15/2008

or is it: 0 years, 8 months, 3 days

what should be the results for these dates:
St date: 12/29/2007
end date: 1/28/2008
0 year, 0 months, 30 days ?

St date: 2/29/2008
end date: 3/29/2008
(0 year, 1 months, 0 days) or (0 years, 0 months, 29 days) or ?



Be One with the Optimizer
TG
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-09-30 : 15:49:32
See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=78730
or http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=62729


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

cognos79
Posting Yak Master

241 Posts

Posted - 2008-09-30 : 16:31:20
peso...does it take leap year into account. the function written by you.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-09-30 : 16:32:57
What were your test-results?



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-09-30 : 16:33:19
quote:
Originally posted by cognos79

peso...does it take leap year into account. the function written by you.



Did you test it?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

cognos79
Posting Yak Master

241 Posts

Posted - 2008-09-30 : 16:57:47
I will test it...thanks guys.
Go to Top of Page
   

- Advertisement -