DateDiff -- Business Hours

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default DateDiff -- Business Hours

    I'm writing a little Help Desk, and would like to show the amount of time
    that a problem takes to be solved.

    If I use DateDiff(hh,.......) then I would get a value of 16 for a problem
    that began at 5pm and was resolved at 9 am the following morning. That
    would look unacceptable to the manager, but is in fact quite acceptable.

    I'm using....

    SELECT DATEDIFF(hh, Problems.DateTimeStamp, StepsTaken.DateTimeStamp) FROM
    etc.etc.

    I'm sure this has come up before, and am curious what people do.

    Thanks

    TOm B


    Tom B Guest

  2. Similar Questions and Discussions

    1. Datediff() bug
      The Datediff("m",startdate,enddate) function does not return the correct value if the startdate is "2/28/05" and the enddate has a day value of...
    2. Datediff Problem
      I am having some difficulties with the function Datediff! I am trying to calculate the number of days between two given date E.G: Number days...
    3. now() datediff inconsistency
      I have a problem with datediff using now() : <cfoutput> <cfset expirychecktoday=createodbcdate(createdate(year(now()),month(now()),day(now())))...
    4. Datediff
      Hello Newsgroup, I have a little problem. I want to know the difference between two dates but I need this in a german format. First Date :...
    5. DateDiff in C#
      Hello, I am attempting to port some VB.NET code to C#.NET and have run across the DateDiff function in VB.NET. Does anyone know what the...
  3. #2

    Default Re: DateDiff -- Business Hours

    Tom B wrote:
    > I'm writing a little Help Desk, and would like to show the amount of
    > time that a problem takes to be solved.
    >
    > If I use DateDiff(hh,.......) then I would get a value of 16 for a
    > problem that began at 5pm and was resolved at 9 am the following
    > morning. That would look unacceptable to the manager, but is in fact
    > quite acceptable.
    >
    > I'm using....
    >
    > SELECT DATEDIFF(hh, Problems.DateTimeStamp,
    > StepsTaken.DateTimeStamp) FROM etc.etc.
    >
    > I'm sure this has come up before, and am curious what people do.
    I fear the answer lies in the domain of whoever is using the reported
    figures and would depend on purpose.

    I suspect you should refrain from making any comment along the lines of
    "give a better service if you want better figures".

    Whatever you do, don't change the data - you'll feel more dirty than a whore
    on her first day - but by all means accept briefs to provide reports that
    show the figures in a more favourable light, perhaps you could build in
    time-of-day sensitive adjustments.

    --
    William Tasso - [url]http://WilliamTasso.com[/url]


    William Tasso Guest

  4. #3

    Default Re: DateDiff -- Business Hours

    Do you want elapsed time or working time?

    For elapsed time you would use datediff as you show.

    For working time you would have the person doing the work enter the time
    they spent on the problem. It is quite possible that a problem will consume
    an hour here and there over a period of several days (weeks, months, ...)
    and the total would be the sum of all the individual time periods.

    --
    Mark Schupp
    Head of Development
    Integrity eLearning
    [url]www.ielearning.com[/url]


    "Tom B" <shuckle@hotmail.com> wrote in message
    news:ee4sZizkDHA.2488@TK2MSFTNGP12.phx.gbl...
    > I'm writing a little Help Desk, and would like to show the amount of time
    > that a problem takes to be solved.
    >
    > If I use DateDiff(hh,.......) then I would get a value of 16 for a problem
    > that began at 5pm and was resolved at 9 am the following morning. That
    > would look unacceptable to the manager, but is in fact quite acceptable.
    >
    > I'm using....
    >
    > SELECT DATEDIFF(hh, Problems.DateTimeStamp, StepsTaken.DateTimeStamp)
    FROM
    > etc.etc.
    >
    > I'm sure this has come up before, and am curious what people do.
    >
    > Thanks
    >
    > TOm B
    >
    >

    Mark Schupp Guest

  5. #4

    Default Re: DateDiff -- Business Hours

    Yes, I appreciate what you are saying.

    I want a manager to be able to answer the question, "How long (on average)
    did the end user have to wait (and theoretically, was unable to work) "

    So, I'm really after--the number of business hours lost.

    Thanks


    "Mark Schupp" <mschupp@ielearning.com> wrote in message
    news:%23lqOTz1kDHA.744@tk2msftngp13.phx.gbl...
    > Do you want elapsed time or working time?
    >
    > For elapsed time you would use datediff as you show.
    >
    > For working time you would have the person doing the work enter the time
    > they spent on the problem. It is quite possible that a problem will
    consume
    > an hour here and there over a period of several days (weeks, months, ...)
    > and the total would be the sum of all the individual time periods.
    >
    > --
    > Mark Schupp
    > Head of Development
    > Integrity eLearning
    > [url]www.ielearning.com[/url]
    >
    >
    > "Tom B" <shuckle@hotmail.com> wrote in message
    > news:ee4sZizkDHA.2488@TK2MSFTNGP12.phx.gbl...
    > > I'm writing a little Help Desk, and would like to show the amount of
    time
    > > that a problem takes to be solved.
    > >
    > > If I use DateDiff(hh,.......) then I would get a value of 16 for a
    problem
    > > that began at 5pm and was resolved at 9 am the following morning. That
    > > would look unacceptable to the manager, but is in fact quite acceptable.
    > >
    > > I'm using....
    > >
    > > SELECT DATEDIFF(hh, Problems.DateTimeStamp, StepsTaken.DateTimeStamp)
    > FROM
    > > etc.etc.
    > >
    > > I'm sure this has come up before, and am curious what people do.
    > >
    > > Thanks
    > >
    > > TOm B
    > >
    > >
    >
    >

    Tom B Guest

  6. #5

    Default Re: DateDiff -- Business Hours

    "Tom B" <shuckle@NOSPAMhotmail.com> wrote in message
    news:ep1JGO2kDHA.392@TK2MSFTNGP11.phx.gbl...
    > Yes, I appreciate what you are saying.
    >
    > I want a manager to be able to answer the question, "How long (on average)
    > did the end user have to wait (and theoretically, was unable to work) "
    >
    > So, I'm really after--the number of business hours lost.
    >

    This is actually quite a complex problem. Even if you make a radical
    assumption such as working hours are Mon-Friday 9-5, then you have to step
    through each day from start to finish, identifying each day as a workday.
    Remember, each month will have a differing number of days and weekdays. Not
    something you could do in database query.

    Then, you perhaps would need to be more realistic - what about
    public/business holidays?

    --
    John Blessing

    [url]http://www.LbeHelpdesk.com[/url] - Help Desk software priced to suit all
    businesses
    [url]http://www.free-helpdesk.com[/url] - Completely free help desk software !
    [url]http://www.lbetoolbox.com[/url] - Remove Duplicates from MS Outlook


    John Blessing Guest

  7. #6

    Default Re: DateDiff -- Business Hours

    Thanks for that.

    I do realize there are complexities involved, I was just wondering if anyone
    had a suggestion. You're right, I completely forgot about weekends and
    holidays.

    Thanks

    "John Blessing" <jb@**REMOVE**THIS**LbeHelpdesk.com> wrote in message
    news:y9jjb.1432$KA5.15458@newsfep4-glfd.server.ntli.net...
    > "Tom B" <shuckle@NOSPAMhotmail.com> wrote in message
    > news:ep1JGO2kDHA.392@TK2MSFTNGP11.phx.gbl...
    > > Yes, I appreciate what you are saying.
    > >
    > > I want a manager to be able to answer the question, "How long (on
    average)
    > > did the end user have to wait (and theoretically, was unable to work) "
    > >
    > > So, I'm really after--the number of business hours lost.
    > >
    >
    >
    > This is actually quite a complex problem. Even if you make a radical
    > assumption such as working hours are Mon-Friday 9-5, then you have to step
    > through each day from start to finish, identifying each day as a workday.
    > Remember, each month will have a differing number of days and weekdays.
    Not
    > something you could do in database query.
    >
    > Then, you perhaps would need to be more realistic - what about
    > public/business holidays?
    >
    > --
    > John Blessing
    >
    > [url]http://www.LbeHelpdesk.com[/url] - Help Desk software priced to suit all
    > businesses
    > [url]http://www.free-helpdesk.com[/url] - Completely free help desk software !
    > [url]http://www.lbetoolbox.com[/url] - Remove Duplicates from MS Outlook
    >
    >

    Tom B Guest

  8. #7

    Default Re: DateDiff -- Business Hours

    > This is actually quite a complex problem. Even if you make a radical
    > assumption such as working hours are Mon-Friday 9-5, then you have to step
    > through each day from start to finish, identifying each day as a workday.
    > Remember, each month will have a differing number of days and weekdays.
    Not
    > something you could do in database query.
    You could, just not trivial. There is an example here that uses days; the
    table would be a bit larger if you had hour divisions, but the logic would
    be similar:
    [url]http://www.aspfaq.com/2453[/url]


    Aaron Bertrand - MVP Guest

  9. #8

    Default Re: DateDiff -- Business Hours

    Thanks Aaron, this is way more complicated then expected.

    "Aaron Bertrand - MVP" <aaron@TRASHaspfaq.com> wrote in message
    news:ej98t2%23kDHA.2444@TK2MSFTNGP09.phx.gbl...
    > > This is actually quite a complex problem. Even if you make a radical
    > > assumption such as working hours are Mon-Friday 9-5, then you have to
    step
    > > through each day from start to finish, identifying each day as a
    workday.
    > > Remember, each month will have a differing number of days and weekdays.
    > Not
    > > something you could do in database query.
    >
    > You could, just not trivial. There is an example here that uses days; the
    > table would be a bit larger if you had hour divisions, but the logic would
    > be similar:
    > [url]http://www.aspfaq.com/2453[/url]
    >
    >

    Tom B Guest

  10. #9

    Default Re: DateDiff -- Business Hours

    you could try this. work out the total hours and then remove the non worked hours

    Private Function calcBusinessHours(ByVal startTime As Date, ByVal endTime As Date) As Integer

    Dim intHours As Integer
    Dim intDays As Integer

    intHours = DateDiff(DateInterval.Hour, startTime, endTime)
    intdays = DateDiff(DateInterval.Day, startTime, endTime)

    ' If the start time and the end time is on the same day then return the total number of hours
    If startTime.Date = endTime.Date Then
    Return intHours
    End If

    For x = 0 To intDays - 1
    If startTime.DayOfWeek Then
    ' -weekdays
    intHours -= 15
    Else
    ' -weekends
    intHours -= 24
    End If
    startTime = startTime.AddDays(1)
    Next

    Return intHours

    End Function
    Unregistered Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139