15,742,619 members
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.

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

Solution 1

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.

v2
basitsar 23-Nov-15 23:53pm
Thanks A lot.

Solution 2

Use this code to get hour
SQL
`DATEDIFF(mi, dbo.Trn_Daily3.Dr_TimeStart, dbo.Trn_Daily3.Dr_TimeEnd)/60.0`

basitsar 23-Nov-15 23:53pm
Thanks A lot.

Solution 3

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

See "/ (Divide) (Transact-SQL)"[^]

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)

Top Experts
Last 24hrsThis month
 merano99 89 OriginalGriff 50 Rick York 25 Dave Kreskowiak 20 Richard MacCutchan 10
 OriginalGriff 1,638 Richard MacCutchan 1,318 merano99 569 Rick York 455 Dave Kreskowiak 286

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