Click here to Skip to main content
16,019,018 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear,

I have two Column Start & End both are Datetime data type.

The Data is

Start End
12:30 15:00

The Total min is 150
i used below query

DATEDIFF(mi, dbo.Trn_Daily3.Dr_TimeStart, dbo.Trn_Daily3.Dr_TimeEnd)

Its giving correct result=150

But when i convert into hour

DATEDIFF(mi, dbo.Trn_Daily3.Dr_TimeStart, dbo.Trn_Daily3.Dr_TimeEnd)/60

then result is 2 but actual 150/60=2.5

How to do it.

Please help on this

Thanks
Basit.
Posted
Updated 19-Nov-15 0:20am
v2

Did you try to divide by a non integer ?
Try to replace
SQL
DATEDIFF(mi, dbo.Trn_Daily3.Dr_TimeStart, dbo.Trn_Daily3.Dr_TimeEnd)/60

with
SQL
DATEDIFF(mi, dbo.Trn_Daily3.Dr_TimeStart, dbo.Trn_Daily3.Dr_TimeEnd)/60.0


as for many languages like C, C++, C#
a divide of integers result in an integer.
 
Share this answer
 
v2
Comments
basitsar 23-Nov-15 23:53pm    
Thanks A lot.
Use this code to get hour
SQL
DATEDIFF(mi, dbo.Trn_Daily3.Dr_TimeStart, dbo.Trn_Daily3.Dr_TimeEnd)/60.0
 
Share this answer
 
Comments
basitsar 23-Nov-15 23:53pm    
Thanks A lot.
Try
SQL
DATEDIFF(mi, dbo.Trn_Daily3.Dr_TimeStart, dbo.Trn_Daily3.Dr_TimeEnd)/60.0


See "/ (Divide) (Transact-SQL)"[^]
 
Share this answer
 
Comments
basitsar 23-Nov-15 23:53pm    
Thanks A lot.
CPallini 24-Nov-15 2:32am    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900