+ Reply to Thread
Results 1 to 12 of 12

Get number of seconds between two dates in excel excluding part of weekend & holidays

  1. #1
    Registered User
    Join Date
    04-23-2022
    Location
    France
    MS-Off Ver
    2016
    Posts
    5

    Question Get number of seconds between two dates in excel excluding part of weekend & holidays

    I have requirement as follow , i want to get number of seconds between two date-times:

    Exemple

    StartTime: 01/04/2022 05:00:00
    EndTime: 30/04/2022 05:00:00

    Excluding :

    weekend with Time for example (Thursday 21:12:45 To Saturday 05:30:50)
    Holidays is list
    a. (01/04/2022 05:00:00 to 02/04/2022 05:00:00)
    b. (30/04/2022 04:00:00 to 30/04/2022 20:00:00)
    c. .....



    Weekends.PNG

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,799

    Re: Get number of seconds between two dates in excel excluding part of weekend & holidays

    Welcome to the forum.

    There are instructions at the top of the page explaining how to attach your sample workbook.

    A good sample workbook has just 10-20 rows of representative data that has been desensitised. It also has expected results mocked up, relevant cells highlighted and a few explanatory notes.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Valued Forum Contributor janmorris's Avatar
    Join Date
    07-24-2021
    Location
    Japan
    MS-Off Ver
    Google Sheets (& Mac 2021)
    Posts
    1,066

    Re: Get number of seconds between two dates in excel excluding part of weekend & holidays

    You need to calculate hours for whole ON days + part day from midnight to end time + from start time to midnight, while excluding the holidays.

    Here is a workbook i created, that by chance (because the weekend time crosses past the beginning of the holiday #2 start time which itself ends before the end of day that has work hours at the end of the day) happens to give the correct value.

    However, i will point out that this is designed for public/national holidays being a full day, and not for part day holidays (for example, that one might use for part day annual leave).

    Here is the main formula (that uses many named ranges, NETWORKDAYS.INTL, MAX, MIN, MOD, etc):

    Please Login or Register  to view this content.
    working solution is in column D of the SLA sheet/tab.

    sample file attached
    Attached Files Attached Files
    As a gesture off appreciation, you can click * Add Reputation at the foot of any of the posts of members who helped you reach a solution.

    And finally, was your problem solved? if so, please click Thread Tools above the first post of your enquiry, then select [Solved]

  4. #4
    Registered User
    Join Date
    04-23-2022
    Location
    France
    MS-Off Ver
    2016
    Posts
    5

    Re: Get number of seconds between two dates in excel excluding part of weekend & holidays

    Thank you M.janmorris for the solution i appreciate it
    I one more quastion where we can specify time in the holiday list
    i check it the time is 00:00:00
    I read that If your business has different working hours for the weekend, then put this on separate rows. on read me but couldn't understand it
    I am trying to add attachment here but it cant be loaded
    Attached Files Attached Files
    Last edited by Nas Ro; 04-25-2022 at 05:49 AM.

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,799

    Re: Get number of seconds between two dates in excel excluding part of weekend & holidays

    In what way?

    Scroll to Manage Attachments, otherwise scroll down to GO ADVANCED, click, and then scroll down to MANAGE ATTACHMENTS and click again. Now follow the instructions at the top of that screen.
    If your workbook is too big, then cut it down. We don't need to see the whole thing - just a sample that demonstrates the issue.

  6. #6
    Valued Forum Contributor janmorris's Avatar
    Join Date
    07-24-2021
    Location
    Japan
    MS-Off Ver
    Google Sheets (& Mac 2021)
    Posts
    1,066

    Re: Get number of seconds between two dates in excel excluding part of weekend & holidays

    If your business has different working hours for the weekend, then put this on separate rows
    in the example file there are 3 rows, where you can set the working hours and the days for those working hours.

    so in your case you have some days are 24 hours, but other days are some other timeframe.

    so on ONE ROW you can do ALL the days that have 24 hours
    then for day where the time ENDS in the middle of the day, you switch the correct column ON (using "0"), and then go from midnight to the end time.
    then for the day where the time STARTS in the middle of the day, but ends at midnight, you switch the correct column ON (using "0"), and then go from start time to midnight.
    (i have already set these 3 rows up in the example file)

    you can add in more rows to the setup configuration sheet by adding in a repetition of a part of the formula, and then adding named ranges where necessary, then modifying it slightly, like this type of pattern:

    Please Login or Register  to view this content.
    but for your example, the 3 rows is what is needed.

    as for the hours start and end of specific day holidays, the system is not yet setup for that.

    i suspect that to include this feature may require some kind of helpers to first create an array of "runs of days" between the original start and end date, and then taking weekends out from each row of the new array.

  7. #7
    Registered User
    Join Date
    04-23-2022
    Location
    France
    MS-Off Ver
    2016
    Posts
    5

    Re: Get number of seconds between two dates in excel excluding part of weekend & holidays

    Could you make an example of helpers
    and what you mean by "runs of days" between the original start and end date, and then taking weekends out from each row of the new array.

  8. #8
    Valued Forum Contributor janmorris's Avatar
    Join Date
    07-24-2021
    Location
    Japan
    MS-Off Ver
    Google Sheets (& Mac 2021)
    Posts
    1,066

    Re: Get number of seconds between two dates in excel excluding part of weekend & holidays

    what you mean
    ...

    lets use plain numbers as an example:

    start with 1 - 100.

    first, taking out the one-off breaks (holidays) from 25.5 - 26.6, and from 51.1 - 51.9

    so now there are three runs of numbers:
    1 - 25.5
    26.6 - 51.1
    51.9 - 100

    now we can take out the regular numbers that occur every week.

    does that make sense?

    where we can specify time in the holiday list
    to answer this previous question... i already stated that the Holidays list is for whole day holidays, it is to be used as deduction in NETWORKDAYS.INTL function.
    it is not designed for using time. see above where i have explained what is really required, and can easily be implemented on the spreadsheet provided. All that you will need is a way to get the "run of datetimes" which you can implement by manually looking at the start datetime and end datetime and then making breaks in this run so you have a list of shorter datetime runs, then sum them together after calculation...

    OR... figure out a way for these (shorter datetime runs) to be calculated and returned in an array/list that can then be put into the SLA sheet/tab.

    i have attached a revised sample that has 5 rows on the SLA tab, which is enough for 4 of your "holidays" to be accounted for... if you want more holidays.. then add more rows.
    Attached Files Attached Files
    Last edited by janmorris; 04-25-2022 at 10:22 AM.

  9. #9
    Registered User
    Join Date
    04-23-2022
    Location
    France
    MS-Off Ver
    2016
    Posts
    5

    Re: Get number of seconds between two dates in excel excluding part of weekend & holidays

    I found difficult to implement holidays Especially when holidays contained weekend that is already subtracted
    I added four holidays with start & end time in the attachment below with four samples period SLA Tab
    could you implement the function
    thank you
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    04-23-2022
    Location
    France
    MS-Off Ver
    2016
    Posts
    5

    Re: Get number of seconds between two dates in excel excluding part of weekend & holidays

    any one could answer me ?

  11. #11
    Valued Forum Contributor janmorris's Avatar
    Join Date
    07-24-2021
    Location
    Japan
    MS-Off Ver
    Google Sheets (& Mac 2021)
    Posts
    1,066

    Re: Get number of seconds between two dates in excel excluding part of weekend & holidays

    As previously stated, the Full Day Holidays are for FULL DAYS ONLY.
    This is because NETWORKDAYS.INTL considers a holiday to be a whole day from midnight to midnight.
    it can NOT be used for a timeframe from datetime1 to datetime2

    the way to implement this is to use the rows of the SLA sheet to be each remaining "uptime" after the holiday hours are removed. from the original time period.

  12. #12
    Valued Forum Contributor janmorris's Avatar
    Join Date
    07-24-2021
    Location
    Japan
    MS-Off Ver
    Google Sheets (& Mac 2021)
    Posts
    1,066

    Re: Get number of seconds between two dates in excel excluding part of weekend & holidays

    @Nas Ro,

    Here is a spreadsheet that will remove the downtimes (holidays) from the original time period, leaving you with just the remaining uptime (available time), which you can then use the values to fill the times in the SLA sheet of file provided in post #8.

    In order to get the remaining uptime, first, the original downtime list is sorted, using this formula:

    Please Login or Register  to view this content.
    then, named ranges are used for the original start time and end times, and also for the range of the downtime start times, and the downtime end times.

    Where the results will be populated starting on row 25, use this formula to populate the remaining start times:

    Please Login or Register  to view this content.
    and this formula for the remaining end times:
    Please Login or Register  to view this content.
    if you change the starting row where your results will be populated, then just change the number 25 throughout the formulas.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Display deadline in workdays (excluding weekend and holidays)
    By vvillanueva in forum Excel General
    Replies: 4
    Last Post: 02-10-2021, 02:33 PM
  2. [SOLVED] Networkdays - excluding weekend and custom list of dates
    By godlev in forum Excel General
    Replies: 2
    Last Post: 12-05-2018, 06:38 AM
  3. [SOLVED] Count Unique Number of Dates, Excluding Designated Holidays and Weekend Dates
    By Winship in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-07-2017, 08:37 AM
  4. [SOLVED] Require a formula to count unique dates excluding weekend dates
    By john dalton in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-09-2015, 09:17 AM
  5. Replies: 1
    Last Post: 08-13-2015, 08:37 AM
  6. Replies: 10
    Last Post: 04-27-2015, 06:33 PM
  7. [SOLVED] VBA code for excluding weekend dates from Web import into Excel
    By vk2013 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-29-2013, 04:15 PM

Tags for this Thread

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