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 difference

Author  Topic 

BankOfficerHere
Posting Yak Master

124 Posts

Posted - 2009-02-12 : 07:27:08
I would like to get the difference of the 2 dates as follows:

2/13/2009 3:45:52 PM

2/12/2009 3:43:36

I want the difference to be in hours. Like in this case 24.7777 something like that.

Thanks

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-12 : 07:28:40
See DateDiff .
Go to Top of Page

BankOfficerHere
Posting Yak Master

124 Posts

Posted - 2009-02-12 : 07:29:29
yes i tried, how's it? thanks
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-02-12 : 07:30:51
select datediff(d,'2/12/2009 3:43:36','2/13/2009 3:45:52')
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-02-12 : 07:31:40
select datediff(mi,'2/12/2009 3:43:36','2/13/2009 3:45:52')
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-02-12 : 07:35:00
See how DATEDIFF calculate the value, here
http://www.sqlteam.com/article/datediff-function-demystified



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

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-02-12 : 07:35:31
SELECT CAST(datediff(hh,'2/12/2009 3:43:36','2/13/2009 3:45:52') AS VARCHAR(32))+
'.'+CAST(datediff(mi,'2/12/2009 3:43:36','2/13/2009 3:45:52') AS VARCHAR(32)) +
'.'+CAST(datediff(ss,'2/12/2009 3:43:36','2/13/2009 3:45:52') AS VARCHAR(32)) as 'DateDiff'
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2009-02-12 : 07:38:04
If u want in hours the use this

select datediff(hh,'2/12/2009 3:43:36','2/13/2009 3:45:52')
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-02-12 : 07:52:32
select datediff(minute,'2/12/2009 3:43:36','2/13/2009 3:45:52') / 60.0E

as per OP requested...



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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-02-12 : 07:53:42
quote:
Originally posted by Nageswar9

SELECT CAST(datediff(hh,'2/12/2009 3:43:36','2/13/2009 3:45:52') AS VARCHAR(32))+
'.'+CAST(datediff(mi,'2/12/2009 3:43:36','2/13/2009 3:45:52') AS VARCHAR(32)) +
'.'+CAST(datediff(ss,'2/12/2009 3:43:36','2/13/2009 3:45:52') AS VARCHAR(32)) as 'DateDiff'

Let's check the result, shall we?

Result
---------------
24.1442.86536

It seems you also need to read the article provided in the link above.



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

- Advertisement -