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 2005 Forums
 Transact-SQL (2005)
 how to find hour diff between 4 fields?

Author  Topic 

sishan81
Starting Member

7 Posts

Posted - 2010-08-03 : 05:37:57
I'll explain..
I have a date field that contains year-month-day and an hour field which contains an hour such as 1420.
how can I get the hour difference between 2010-05-02 14:20 and 2010-05-05 15:40?
Thanks in advance!!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-08-03 : 05:42:34
which field has the value 2010-05-05 15:40?

for first part use

SELECT DATEDIFF(DATEADD(n,hourfield%100,DATEADD(hh,hourfield/100,datefield)),secondfield) FROM Table


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sishan81
Starting Member

7 Posts

Posted - 2010-08-03 : 07:20:02
It says: "The datediff function requires 3 argument(s)."

SELECT DATEDIFF(DATEADD(n,1540%100,DATEADD(hh,1420/100,2010-05-02)),2010-05-05)
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-08-03 : 08:44:34
Which datatypes are the two columns?



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

sishan81
Starting Member

7 Posts

Posted - 2010-08-03 : 10:27:12
It worked! thanks a lot
Go to Top of Page
   

- Advertisement -