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
 Data Type Frustration

Author  Topic 

DavidChel
Constraint Violating Yak Guru

474 Posts

Posted - 2009-02-13 : 10:25:33
I'm doing a DateDiff on 2 date time values to get the number of seconds.

DATEDIFF("s", ladetail.fsdatetime, ladetail.fedatetime)


This gives me seconds and I want to convert that to decimal portions of an hour. I can't seem to do that. The hours I get are all round numbers. For example 2232 seconds becomes 0 hours.

So, I tried the following:

convert(numeric(6,2),(DATEDIFF("s", ladetail.fsdatetime, ladetail.fedatetime)/3600)) as [HoursWorked]


And that gives me 0.00 for the HoursWorked value.

Any ideas?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-13 : 10:54:07
just use:-
(DATEDIFF("s", ladetail.fsdatetime, ladetail.fedatetime)/3600.0) as [HoursWorked]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-13 : 10:55:25
reason is this

http://sqlblogcasts.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx
Go to Top of Page

DavidChel
Constraint Violating Yak Guru

474 Posts

Posted - 2009-02-13 : 10:56:45
Thanks man, you're the best.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-13 : 10:58:01
welcome
Go to Top of Page
   

- Advertisement -