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
 want to get the difference in hh.mm

Author  Topic 

pnasz
Posting Yak Master

101 Posts

Posted - 2010-12-08 : 08:18:00
want to get the difference in hh.mm can anyone help


(case when (0)>((CONVERT([float],datediff(minute,[EmpSIN],[EmpSOut])/(60),(0))+CONVERT([float],(datediff(minute,[EmpSIN],[EmpSOut])%(60))/(100.0),(0)))-(CONVERT([float],datediff(minute,[FirstIn],[FirstOut])/(60),(0))+CONVERT([float],(datediff(minute,[FirstIn],[FirstOut])%(60))/(100.0),(0)))) then (0) else (CONVERT([float],datediff(minute,[EmpSIN],[EmpSOut])/(60),(0))+CONVERT([float],(datediff(minute,[EmpSIN],[EmpSOut])%(60))/(100.0),(0)))-(CONVERT([float],datediff(minute,[FirstIn],[FirstOut])/(60),(0))+CONVERT([float],(datediff(minute,[FirstIn],[FirstOut])%(60))/(100.0),(0))) end)

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2010-12-08 : 09:25:19
Not sure what you're after as you didn't post sample data with expected output, but this may help you.

declare @startDate datetime
declare @endDate datetime


set @startDate = current_timestamp

set @endDate = dateadd(minute,abs(checksum(newid()))/1000000,@startdate)


select @startdate
,@enddate
,datediff(minute,@startdate,@enddate)
,datediff(minute,@startdate,@enddate) / 60
,datediff(minute,@startdate,@enddate) % 60
,(datediff(minute,@startdate,@enddate) % 60)/60.0
,datediff(minute,@startdate,@enddate) / 60 + (datediff(minute,@startdate,@enddate) % 60)/60.0


Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-12-08 : 09:26:43
SELECT CONVERT(CHAR(5), DATEADD(MINUTE, DATEDIFF(MINUTE, EmpSin, EmpSout), 0), 108),
CONVERT(CHAR(5), DATEADD(SECOND, DATEDIFF(SECOND, EmpSin, EmpSout), 0), 108)




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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-12-11 : 07:48:18
SELECT REPLACE(CONVERT(CHAR(5), DATEADD(SECOND, DATEDIFF(SECOND, EmpSin, EmpSout), 0), 108), ':', '.')



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

- Advertisement -