+ Reply to Thread
Results 1 to 4 of 4

Calculate hours between 2 dates/times

  1. #1
    Registered User
    Join Date
    12-09-2010
    Location
    NY, NY
    MS-Off Ver
    Excel 2007
    Posts
    8

    Cool Calculate hours between 2 dates/times

    There are 2 dates written as, for example, in one cell, say 12/2/2010 3:30 PM and another cell, say 12/7/2010 10:20 PM. The calculation that is needed is the following:

    1) Total hours excluding weekends if the start and end times are not BOTH on the weekend. Also, just to be clear, a weekend is from midnight Sat to midnight Mon.

    2) If either date, or both dates, falls on a weekend, then the weekend should be included.

    3) The dates can span over weeks. I'm not sure what to do if the start and end dates are on the weekends here. It doesn't matter much for spans > 9 days if the weekends count or not. Your choice.

    4) The output should be in a 'number' format that can be graphed; so, a 48 hour span should be graphed as the number 48.

    5) The calculation can be accurate to within 3 hours; if that helps.

    If this cannot be 'easily' handled, what is your closest approximation to the above?

    If desired, I can give examples of all of the above scenarios in an excel spreadsheet.

    Many thanks in advance!!!!!

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Calculate hours between 2 dates/times

    Quote Originally Posted by cords
    If desired, I can give examples of all of the above scenarios in an excel spreadsheet.
    That would be good - detail expected results for each example of course.

  3. #3
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Re: Calculate hours between 2 dates/times

    Possibly :-

    =(IF(OR(MOD(A1,7)<2,MOD(B1,7)<2),(ROUNDUP(A1,0)-(ROUNDDOWN(B1,0)-"00:00:01")),NETWORKDAYS(ROUNDUP(A1,0),ROUNDDOWN(B1,0)-"00:00:01"))+MOD(B1-A1,1))*24

    if either day is a weekend then include weekends, otherwise only include working days

    it should be accurate to 1 second
    Regards
    Darren

    Update 12-Nov-2010 Still job hunting!

    If you are happy with the results, please add to our reputation by clicking the blue scales icon in the blue bar of the post.

    Learn something new each day, Embrace change do not fear it, evolve and do not become extinct!


  4. #4
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Calculate hours between 2 dates/times

    Hello Darren,

    when I use that formula using cords' example dates I get a result of 54.83. I think that's 24 hours too little, the total hours between them is 126.83, with 2 weekend days so shouldn't the result be 78.83?

    This version should give the correct hours, I think

    =IF(NETWORKDAYS(A1,A1)+NETWORKDAYS(B1,B1)<2,B1-A1,NETWORKDAYS(A1,B1)-1+MOD(B1,1)-MOD(A1,1))*24

    where start date/time is in A1 and end date.time in B1

    format result cell as number

    It counts all hours between A1 and B1 if either of the dates is at the weekend, otherwise it excludes weekends
    Audere est facere

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1