Wednesday, March 7, 2012

hours cal

Dear frinends
I need to substract the hours. I need to calculate the hours worked after 6:00pm.
input is strat time like 30:june:03:30 PM until 8:00pm in night
I need to calculate the hours he worked after 6:00pm.
please help
elamsomething like this?

declare @.d datetime
set @.d = dateadd(hh,-12,getdate())
select @.d
, dateadd(hh,18,convert(varchar(10),@.d,120))
, datediff(hh,dateadd(hh,18,convert(varchar(10),@.d,1 20)),@.d)|||This calculates minutes worked after 6 pm. You could change it to calculate hours if you don't want the extra accuracy.

select (datediff(mi, convert(varchar(10), @.d, 120) + ' 18:00', @.d) + abs(datediff(mi, convert(varchar(10), @.d, 120) + ' 18:00', @.d)))/2

The absolute value conversion is used to return 0 instead of negative hours.

No comments:

Post a Comment