+ Reply to Thread
Results 1 to 7 of 7

Calculating Working Hours Between Two Dates & Times [MON-FRI and SAT, SUN excluded]?

  1. #1
    Registered User
    Join Date
    01-05-2013
    Location
    Kranj, Slovenia
    MS-Off Ver
    Excel 2003
    Posts
    7

    Calculating Working Hours Between Two Dates & Times [MON-FRI and SAT, SUN excluded]?

    Hi,

    I kindly ask all you experts to help me calculate working hours inside the following hours:
    MON-FRI 8:00AM-6:00PM and on SAT 8:00AM-1:00PM, SUN closed

    The formula must not calculate times outside the working hours.


    I have try following formula, but it also calculates SUNDAYS. Anyone knows how to modify this formula to exclude SUNDAYS?

    =SUM(INT((WEEKDAY(E4-{0;1})+INT(E5)-INT(E4))/7)*($V$7-$U$7);INT((WEEKDAY(E4-{2;3;4;5;6})+INT(E5)-INT(E4))/7)*($T$7-$S$7))-IF(WEEKDAY(E4;2)>5;MEDIAN(0;MOD(E4;1)-$U$7;$V$7-$U$7);MEDIAN(0;MOD(E4;1)-$S$7;$T$7-$S$7))-IF(WEEKDAY(E5;2)>5;MEDIAN(0;$V$7-MOD(E5;1);$V$7-$U$7);MEDIAN(0;$T$7-MOD(E5;1);$T$7-$S$7))

    Where:
    E4 - START WORKING DATE & TIME
    E5 - STOP WORKING DATE & TIME
    S7 - SHOP OPENING HOURS [MON-FRI]
    T7 - SHOP CLOSING HOURS [MON-FRI]
    U7 - SHOP OPENING HOURS [SAT]
    V7 - SHOP CLOSING HOURS [SAT]


    Thanks & Regards

    miki12

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Calculating Working Hours Between Two Dates & Times [MON-FRI and SAT, SUN excluded]?

    Hi,

    I think you need to upload a workbook with some sample dates & time and the results you expect to see. It's not immediately obvious how your rules are applied given the use of Median and Mod functions in your current formula.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

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

    Re: Calculating Working Hours Between Two Dates & Times [MON-FRI and SAT, SUN excluded]?

    Hello miki12, welcome to Excel Forum

    See attached - it isn't specifically adapted for your setup but perhaps you can adjust accordingly

    A2 has start time/date, B2 end time/date and F2:H8 contains a table containing the work times for each day - you can adjust the work times as required, just change start and/or end times for each day and column H will update with the duration. Formula is as follows to calculate the work hours

    =SUMPRODUCT(INT((WEEKDAY(A2-{1;2;3;4;5;6;7})+INT(B2)-INT(A2))/7),H$2:H$8)-MEDIAN(0,MOD(A2,1)-INDEX(F$2:F$8,WEEKDAY(A2)),INDEX(H$2:H$8,WEEKDAY(A2)))-MEDIAN(0,INDEX(G$2:G$8,WEEKDAY(B2))-MOD(B2,1),INDEX(H$2:H$8,WEEKDAY(B2)))

    times/dates in columns A and B are randomly generated, press F9 to re-generate or enter your own data to test

    Note that the above formula copes with any start/end times, even on Sundays or evenings outside work hours. If all you start/end times are always within working hours the formula can be simplified
    Attached Files Attached Files
    Last edited by daddylonglegs; 01-05-2013 at 09:18 PM.
    Audere est facere

  4. #4
    Registered User
    Join Date
    01-05-2013
    Location
    Kranj, Slovenia
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Calculating Working Hours Between Two Dates & Times [MON-FRI and SAT, SUN excluded]?

    Here is example workbook

    miki12
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    01-05-2013
    Location
    Kranj, Slovenia
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Calculating Working Hours Between Two Dates & Times [MON-FRI and SAT, SUN excluded]?

    Thanks daddylonglegs,
    That is exactly what I have been looking for.

    You are awesome.

    Regards

    miki12

  6. #6
    Forum Expert Kevin UK's Avatar
    Join Date
    12-07-2010
    Location
    Radstock, Somerset
    MS-Off Ver
    365
    Posts
    1,922

    Re: Calculating Working Hours Between Two Dates & Times [MON-FRI and SAT, SUN excluded]?

    Hi

    Would it not be easier to redesign the worksheet to simplify it.
    Regards Kevin


    Merged Cells (They are the work of the devil!!!)

  7. #7
    Registered User
    Join Date
    01-05-2013
    Location
    Kranj, Slovenia
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Calculating Working Hours Between Two Dates & Times [MON-FRI and SAT, SUN excluded]?

    Hi Kevin UK,

    Well, all options are open, you can modify the worksheet freely.

    The important thing here is formula that calculates dates and times as needed.

    Regards

    miki12

+ 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