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
 DateDiff results automatically rounds off

Author  Topic 

FusionFashion
Starting Member

9 Posts

Posted - 2010-06-21 : 22:11:25
Hi.

I have a problem on my DateDiff result. For example the result is 3.5, it will only show 3. How can i control that?

This is my satatement
SELECT DATEDIFF(hour,dbo.tblAttendanceDetail.TimeIn, dbo.tblAttendanceDetail.TimeOut) - dbo.tblAttendanceDetail.BreakHours
FROM dbo.tblAttendanceDetail

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-06-21 : 22:21:19
datediff always return an integer value.

If you want the different in 2 dates in terms of hour with decimal places, find the different in minutes and then divide by 60.0

DATEDIFF(minute,dbo.tblAttendanceDetail.TimeIn, dbo.tblAttendanceDetail.TimeOut) / 60.0



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

FusionFashion
Starting Member

9 Posts

Posted - 2010-06-21 : 22:24:48
Thank you for the information. I will try your suggestion.
Go to Top of Page

FusionFashion
Starting Member

9 Posts

Posted - 2010-06-21 : 23:00:02
This is now close. I will always remember that DateDiff is an integer value.

Thank you for your help.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-06-21 : 23:04:20
You are welcome


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -