SOLVED
Home

Formula Help

%3CLINGO-SUB%20id%3D%22lingo-sub-327065%22%20slang%3D%22en-US%22%3EFormula%20Help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-327065%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3BI%20need%20some%20help%20I%20trying%20to%20create%20a%20formula%20between%20two%20date%20%2F%20time%20ranges.%20The%20day%20%2F%20time%20format%20I'm%20using%20is%2021%2F01%2F2019%2008%3A45%3A03.%20So%20I%20need%20to%20calculate%20the%20time%20difference%20between%20two%20dates%20and%20times%20as%26nbsp%3Bbelow%20example%20%3A%3C%2FP%3E%3CP%3E21%2F01%2F2019%2008%3A45%3A03%20(Date%201)%3C%2FP%3E%3CP%3E1%2F22%2F2019%2011%3A01%3A27%20AM%20(Date%202)%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%26nbsp%3BHowever%20there%20are%20several%20exclusions%20which%20are%20%3A%3C%2FP%3E%3CP%3E%26nbsp%3BThe%20hours%20I%20need%20to%20calculate%20are%20working%20hours%20between%2007%3A30%20and%2018%3A00%20Monday%20to%20Friday%20only.%20Any%20times%20and%20days%20outside%20of%20this%20need%20to%20be%20ignored.%3C%2FP%3E%3CP%3E%26nbsp%3BWhat's%20the%20best%20%2F%20easiest%20way%20to%20do%20this%20please%20%3F%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EAlso%20I%20need%20to%20exclude%20UK%20bank%20holidays%20as%20well%20as%20weekends%20thanks%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-327065%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-330710%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20Help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-330710%22%20slang%3D%22en-US%22%3EExcellent%20thanks%20again%20all%20working.%20Appreciate%20your%20help%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-330162%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20Help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-330162%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWith%20seconds%3C%2FP%3E%0A%3CPRE%3E%3DN(%22Full%20workdays%20between%20next%20after%20Start%20and%20previous%20to%20End%22)%2B%0ANETWORKDAYS(A5%2B1%2CB5-1%2CHolidayList)*((INT(B5)-INT(A5))%26gt%3B1)%26amp%3B%22%20days%20%22%26amp%3B%0ATEXT(N(%22Start%20and%20End%20are%20not%20the%20same%22)%2B(INT(B5)%26lt%3B%26gt%3BINT(A5))*%0A(%0A(WEEKDAY(A5%2C2)%26lt%3B6)*((A5-INT(A5))%26lt%3B%3D%24B%242)*(%24B%242-MAX(A5-INT(A5)%2C%24A%242))%2B%0A(WEEKDAY(B5%2C2)%26lt%3B6)*((B5-INT(B5))%26gt%3B%3D%24A%242)*(MIN(B5-INT(B5)%2C%24B%242)-%24A%242)%0A)%2BN(%22Start%20and%20End%20are%20the%20same%22)%2B%0A(INT(B5)%3DINT(A5))*%0A((B5-INT(B5))%26gt%3B%3D%24A%242)*((A5-INT(A5))%26lt%3B%3D%24B%242)*%0A(MIN(B5-INT(B5)%2C%24B%242)-MAX(A5-INT(A5)%2C%24A%242))%2C%22%5Bh%5D%22%22%20hours%20%22%22m%22%22%20minutes%20%22%22s%22%22%20seconds%22%22%22)%3C%2FPRE%3E%0A%3CP%3E(format%20in%20last%20string%20is%20changed)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EDates%20in%20column%20H%20are%20holidays%20if%20any.%20In%20formula%20that%20is%20named%20range%20HolidayList.%20You%20may%20change%20that%20in%20Formulas-%26gt%3BName%20Manager%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20548px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F71846iB9ED430577FDAB4F%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image.png%22%20title%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Eor%20use%20in%20formula%20the%20range%20directly%20like%3C%2FP%3E%0A%3CPRE%3E...NETWORKDAYS(A5%2B1%2CB5-1%2C%3CFONT%20color%3D%22%23FF0000%22%3E%3CSTRONG%3E%24H%241%3A%24H10%3C%2FSTRONG%3E%3C%2FFONT%3E)*((INT(B5)-INT(A5))%26gt%3B1)%26amp%3B...%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-330148%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20Help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-330148%22%20slang%3D%22en-US%22%3EThanks%20Sergei%3CBR%20%2F%3E%3CBR%20%2F%3ESorry%20for%20delayed%20reply.%20Looks%20good.%20Two%20final%20questions%20%3A%3CBR%20%2F%3E%3CBR%20%2F%3E1.%20Can%20you%20update%20formula%20to%20include%20seconds%20%3F%3CBR%20%2F%3E%3CBR%20%2F%3E2.%20What%20do%20the%20dates%20in%20column%20H%20refer%20to%20%3F%3CBR%20%2F%3E%3CBR%20%2F%3EMany%20thanks%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-328707%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20Help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-328707%22%20slang%3D%22en-US%22%3E%3CP%3ESorry%2C%20missed%20that.%20You%20took%20not-modified%20formula%2C%20the%20latest%20one%20in%20my%20previous%20post%20and%20in%20attached%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-328589%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20Help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-328589%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Sergei%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20thoughts%20or%20updates%20on%20my%20last%20note%20thanks%20%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-328087%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20Help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-328087%22%20slang%3D%22en-US%22%3E%3CP%3EMir%2C%20so%20far%20so%20good%2C%20glad%20to%20help%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-328038%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20Help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-328038%22%20slang%3D%22en-US%22%3EHi%20Sergei%2C%3CBR%20%2F%3E%3CBR%20%2F%3EIt%20did%20work!%20You%20are%20brilliant.%20%3A)%3CBR%20%2F%3E%3CBR%20%2F%3EMany%20thanks!%3CBR%20%2F%3E%3CBR%20%2F%3E-Mir%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-327860%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20Help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-327860%22%20slang%3D%22en-US%22%3E%3CP%3ESorry%20Sergei%20I%20missed%20that.%20I've%20taken%20a%20copy%20of%20that%20file%20and%20made%20some%20changes%20but%20I%20do%20not%20think%20the%20formula%20is%20working%20correctly.%20I've%20uploaded%20a%20copy%20of%20the%20file%20and%20my%20changes%20are%20located%20in%20the%20%22Modified%22%20column.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20initially%20thought%20this%20was%20because%20cell%20references%20A2%20and%20B23%20were%20not%20absolute%20but%20adding%20the%20dollar%20signs%20in%20the%20formula%20does%20not%20help.%20Any%20ideas%20thanks%20%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%20can%20we%20extend%20the%20formula%20to%20measure%20days%2C%20hours%2C%20minutes%20and%20seconds%20thanks%20%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-327655%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20Help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-327655%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Mir%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENot%20sure%20I%20tested%20all%20variant%2C%20the%20formula%20looks%20like%3C%2FP%3E%0A%3CPRE%3E%3D%20N(%22Full%20workdays%20between%20next%20after%20Start%20and%20previous%20to%20End%22)%2B%0A%20%20%20NETWORKDAYS(A5%2B1%2CB5-1%2CHolidayList)*((INT(B5)-INT(A5))%26gt%3B1)%26amp%3B%22%20days%20%22%20%26amp%3B%0A%20%20%20TEXT(%20N(%22Start%20and%20End%20are%20not%20the%20same%22)%2B(INT(B5)%26lt%3B%26gt%3BINT(A5))*%0A%20%20%20%20%20%20(%0A%20%20%20%20%20%20%20%20%20(WEEKDAY(A5%2C2)%26lt%3B6)*((A5-INT(A5))%26lt%3B%3D%24B%242)*(%24B%242-MAX(A5-INT(A5)%2C%24A%242))%2B%0A%20%20%20%20%20%20%20%20%20(WEEKDAY(B5%2C2)%26lt%3B6)*((B5-INT(B5))%26gt%3B%3D%24A%242)*(MIN(B5-INT(B5)%2C%24B%242%20)%20-%24A%242%20)%0A%20%20%20%20%20%20)%20%2B%20N(%22Start%20and%20End%20are%20the%20same%22)%20%2B%0A%20%20%20%20%20%20%20%20%20(INT(B5)%3DINT(A5))*%0A%20%20%20%20%20%20%20%20%20%20%20%20((B5-INT(B5))%26gt%3B%3D%24A%242)*((A5-INT(A5))%26lt%3B%3D%24B%242)*%0A%20%20%20%20%20%20%20%20%20%20%20%20%20(MIN(B5-INT(B5)%2C%24B%242)-MAX(A5-INT(A5)%2C%24A%242))%2C%22%5Bh%5D%22%22%20hours%20%22%22m%22%22%20minutes%22%22%22)%3C%2FPRE%3E%0A%3CP%3Eand%20in%20attached%20file.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-327475%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20Help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-327475%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Mir%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAssumption%20was%20Start%20and%20End%20are%20always%20within%20office%20hours%2C%20it%20looks%20like%20that's%20not%20your%20case.%20I'll%20check%20how%20to%20correct%20the%20formula.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-327461%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20Help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-327461%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Sergei%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20trying%20to%20follow%20this%20thread%20as%20well%20and%20tried%20using%20your%20formula%20but%20it%20seems%20like%20it's%20not%20working%20for%20me%20(or%20maybe%20I%20am%20doing%20it%20incorrectly).%20I%20edited%20the%20values%20based%20on%20my%20preference%20and%20at%20the%20same%20time%20removed%20the%20holidays.%20The%20result%20I%20am%20expecting%20(based%20on%20the%20example)%20should%20be%204%20hours%20and%201%20minute%20as%2012-2-2018%20fell%20on%20a%20Sunday.%3C%2FP%3E%3CP%3ECan%20you%20please%20check%20and%20tell%20me%20what%20am%20I%20doing%20incorrectly%3F%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-left%22%20style%3D%22width%3A%20851px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F71360i8A6900C8A0C2086D%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22clip.png%22%20title%3D%22clip.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EThanks%2C%3C%2FP%3E%3CP%3EMir%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-327314%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20Help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-327314%22%20slang%3D%22en-US%22%3E%3CP%3EDid%20you%20check%20the%20file%20attached%20to%20the%20last%20post%20in%20that%20thread%3F%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20974px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F71331i8F97CFDD9A075DDE%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image.png%22%20title%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ENETWORKDAYS%20calculates%20only%20working%20days%20in%20your%20locale%20(you%20may%20use%20NETWORKDAYS.INTL%20for%20more%20flexibility)%2C%20holidays%20are%20in%20column%20H%2C%20office%20hours%20start%2Ffinish%20are%20in%20A2%20and%20B2%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-327266%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20Help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-327266%22%20slang%3D%22en-US%22%3EThanks%3CBR%20%2F%3E%3CBR%20%2F%3EOK%20this%20formula%20works%20out%20the%20time%20difference.%20How%20do%20I%20exclude%20weekends%20(Saturdays%2C%20Sundays)%2C%20bank%20holidays%20and%20any%20hours%20outside%20the%20working%20window%20of%2007%3A30%20and%2018%3A00%20thanks%20%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-327128%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20Help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-327128%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPlease%20check%20this%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FExcel%2FCalculating-and-expressing-time-worked-as-days-hours-minutes%2Fm-p%2F278493%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FExcel%2FCalculating-and-expressing-time-worked-as-days-hours-minutes%2Fm-p%2F278493%3C%2FA%3E%20thread%2C%20that's%20a%20similar%20task%3C%2FP%3E%3C%2FLINGO-BODY%3E
thunderthumbs
Occasional Contributor

Hi,

 I need some help I trying to create a formula between two date / time ranges. The day / time format I'm using is 21/01/2019 08:45:03. So I need to calculate the time difference between two dates and times as below example :

21/01/2019 08:45:03 (Date 1)

1/22/2019 11:01:27 AM (Date 2)


 However there are several exclusions which are :

 The hours I need to calculate are working hours between 07:30 and 18:00 Monday to Friday only. Any times and days outside of this need to be ignored.

 What's the best / easiest way to do this please ?


Also I need to exclude UK bank holidays as well as weekends thanks

 

 

14 Replies
Thanks

OK this formula works out the time difference. How do I exclude weekends (Saturdays, Sundays), bank holidays and any hours outside the working window of 07:30 and 18:00 thanks ?

Did you check the file attached to the last post in that thread?

image.png

NETWORKDAYS calculates only working days in your locale (you may use NETWORKDAYS.INTL for more flexibility), holidays are in column H, office hours start/finish are in A2 and B2

Hi Sergei,

 

I am trying to follow this thread as well and tried using your formula but it seems like it's not working for me (or maybe I am doing it incorrectly). I edited the values based on my preference and at the same time removed the holidays. The result I am expecting (based on the example) should be 4 hours and 1 minute as 12-2-2018 fell on a Sunday.

Can you please check and tell me what am I doing incorrectly?clip.png

Thanks,

Mir

Hi Mir,

 

Assumption was Start and End are always within office hours, it looks like that's not your case. I'll check how to correct the formula.

Hi Mir,

 

Not sure I tested all variant, the formula looks like

= N("Full workdays between next after Start and previous to End")+
   NETWORKDAYS(A5+1,B5-1,HolidayList)*((INT(B5)-INT(A5))>1)&" days " &
   TEXT( N("Start and End are not the same")+(INT(B5)<>INT(A5))*
      (
         (WEEKDAY(A5,2)<6)*((A5-INT(A5))<=$B$2)*($B$2-MAX(A5-INT(A5),$A$2))+
         (WEEKDAY(B5,2)<6)*((B5-INT(B5))>=$A$2)*(MIN(B5-INT(B5),$B$2 ) -$A$2 )
      ) + N("Start and End are the same") +
         (INT(B5)=INT(A5))*
            ((B5-INT(B5))>=$A$2)*((A5-INT(A5))<=$B$2)*
             (MIN(B5-INT(B5),$B$2)-MAX(A5-INT(A5),$A$2)),"[h]"" hours ""m"" minutes""")

and in attached file.

Sorry Sergei I missed that. I've taken a copy of that file and made some changes but I do not think the formula is working correctly. I've uploaded a copy of the file and my changes are located in the "Modified" column.

 

I initially thought this was because cell references A2 and B23 were not absolute but adding the dollar signs in the formula does not help. Any ideas thanks ?

 

Also can we extend the formula to measure days, hours, minutes and seconds thanks ?

Hi Sergei,

It did work! You are brilliant. :)

Many thanks!

-Mir

Mir, so far so good, glad to help

Hi Sergei,

 

Any thoughts or updates on my last note thanks ?

Sorry, missed that. You took not-modified formula, the latest one in my previous post and in attached

Thanks Sergei

Sorry for delayed reply. Looks good. Two final questions :

1. Can you update formula to include seconds ?

2. What do the dates in column H refer to ?

Many thanks
Solution

Hi,

 

With seconds

=N("Full workdays between next after Start and previous to End")+
NETWORKDAYS(A5+1,B5-1,HolidayList)*((INT(B5)-INT(A5))>1)&" days "&
TEXT(N("Start and End are not the same")+(INT(B5)<>INT(A5))*
(
(WEEKDAY(A5,2)<6)*((A5-INT(A5))<=$B$2)*($B$2-MAX(A5-INT(A5),$A$2))+
(WEEKDAY(B5,2)<6)*((B5-INT(B5))>=$A$2)*(MIN(B5-INT(B5),$B$2)-$A$2)
)+N("Start and End are the same")+
(INT(B5)=INT(A5))*
((B5-INT(B5))>=$A$2)*((A5-INT(A5))<=$B$2)*
(MIN(B5-INT(B5),$B$2)-MAX(A5-INT(A5),$A$2)),"[h]"" hours ""m"" minutes ""s"" seconds""")

(format in last string is changed)

 

Dates in column H are holidays if any. In formula that is named range HolidayList. You may change that in Formulas->Name Manager

image.png

 

or use in formula the range directly like

...NETWORKDAYS(A5+1,B5-1,$H$1:$H10)*((INT(B5)-INT(A5))>1)&...
Excellent thanks again all working. Appreciate your help
Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
46 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
29 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
13 Replies