Click here to Skip to main content
15,569,696 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to calculate sum of working hours of employee into HH:MM:SS and total numbers of days in decimal..

This is my Query...But I'm not getting the actual sum of total hours:minutes:seconds

I want the output like this.

sum of working hours ="52:02:04" and total days=6.5 days (per day 8 hours)

What I have tried:

select isnull(CONVERT(char(8), DATEADD(HH,SUM(DATEDIFF(MINUTE,FROMTIME,TOTIME)), ''), 114),'00:00:00') as 'TotalHours',isnull((sum(DATEDIFF(HH,FROMTIME,TOTIME))/8),'0') as 'TotalDay' FROM TRNSWRKPROGRESS 
Posted
Updated 16-May-17 21:07pm
v3

1 solution

Finally I got solution..It's working good...

select 
cast(sum(datediff(second,FROMTIME,TOTIME))/3600 as varchar(12)) + ':' + 
        right('0' + cast(sum(datediff(second,FROMTIME,TOTIME))/60%60 as varchar(2)),2) +
        ':' + right('0' + cast(sum(datediff(second,FROMTIME,TOTIME))%60 as varchar(2)),2) as 'Total Hours',
        CAST(sum(DATEDIFF(SECOND, FROMTIME, TOTIME)/28800.0) AS DECIMAL(5,2)) as 'Totaldays'
         from  TRNSWRKPROGRESS 
 
Share this answer
 
v2

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