Link to home
Start Free TrialLog in
Avatar of andy_booth
andy_boothFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Advanced Datediff?

I have two fields, columns A and B
Both are datetime

A contains date / time a call is logged. B contains the time the call was resolved.

For SLA checking, I need to know how many hours difference there is between them, quite simple so far.

The problem is, the calculation needs to take into account the working day. i.e. 9-5 for example.

So, if a call is logged at 4pm then there is only 1 hour of the SLA time used for the current day and the clock so to speak carrys on again from 9am the next day. Meaning the engineer has until 11am the following day. Thats what I need to show.

Anyone able to help?
Avatar of mcmonap
mcmonap
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi andy_booth,

How about something along the lines below.  This just checks whether the call was open for more than one day, if that is the case then the number of hours is calculated less 16 (number of hours between 5pm and 9am) multiplied by the number of days.

--start code
DECLARE @tblDates TABLE (logged datetime, resolved  datetime)
INSERT INTO @tblDates VALUES (getdate(), DATEADD(mi,95,getdate()))
INSERT INTO @tblDates VALUES (getdate(), DATEADD(mi,1395,getdate()))
INSERT INTO @tblDates VALUES (getdate(), DATEADD(mi,2795,getdate()))
INSERT INTO @tblDates VALUES (getdate(), DATEADD(mi,2995,getdate()))

SELECT
      logged
      , resolved
      , CASE
            WHEN DATEDIFF(dd, logged, resolved) > 0 THEN DATEDIFF(hh, logged, resolved) - (DATEDIFF(dd, logged, resolved) * 16)
            ELSE DATEDIFF(hh, logged, resolved)
      END WorkingHoursToResolve
FROM
      @tblDates
--end code
Avatar of andy_booth

ASKER

Thanks mcmonap

That looks like it would kind of work. Except, what would happen on a Friday, Saturday and Sunday are non working days.

Sorry, maybe I should have said that, assumptions are evil :)

Also, could it be adpated slightly to work on two columns?
For those that have a resolved date, for it to work as is i.e. "Resolved in", for those that the resolved date is empty, for it to work out time remaining.

I will increase the points due to my scope creep.
Avatar of Lowfatspread
so you've got the working shift problem,
and the public holiday problem

i'm surprised that you haven't got the "Call on Hold" situation and
multiple people working on call calculations as well ...

presumably a call can be raised and resolved out of the chargeable hours as well....


For the time being, I would be happy with it working with just 9-5 Mon - Fri.

ASKER CERTIFIED SOLUTION
Avatar of mcmonap
mcmonap
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial