Consulting

Results 1 to 16 of 16

Thread: formula to calculate difference between 2 days excluding weekend or other holidays

  1. #1
    VBAX Regular
    Joined
    Dec 2012
    Posts
    55
    Location

    formula to calculate difference between 2 days excluding weekend or other holidays

    Hi

    I am trying to calculate the difference between 2 dates including time.

    I have modified the networkdays formula to get the results but still it shows incorrect date and time.

    =NETWORKDAYS(A2,B2,RDATA!$AC$2:$AC$71)-IF(MOD(A2,1)<=MOD(B2,1),0,1)&"\"&TEXT(B2-A2,"hh")&"\"&RIGHT(TEXT(B2-A2,"hh:mm"),2)
    Example:

    Start Date: 22/06/2015 22:19

    End Date:22/06/2015 22:49

    Result I Got: 1\00\30

    But result should be 0\00\30

    Regards
    Rem0

  2. #2
    VBAX Regular
    Joined
    Dec 2012
    Posts
    55
    Location
    Hi

    Can you anyone advise on the query?

    Best
    Rem0

  3. #3
    VBAX Regular
    Joined
    Dec 2012
    Posts
    55
    Location
    HI can any one help on this, still going in circles.

  4. #4
    VBAX Regular
    Joined
    Dec 2012
    Posts
    55
    Location
    Digged in further and the below formula works fine for dates within a month and its not working as expected if the dates between 2 months.

    =NETWORKDAYS(A2,B2,RDATA!$AC$2:$AC$71)-1&"\"&TEXT(B2-A2,"hh")&"\"&RIGHT(TEXT(B2-A2,"hh:mm"),2)
    Any help/ guidance is much awaited.

    Best
    Rem0

  5. #5
    VBAX Regular
    Joined
    Dec 2012
    Posts
    55
    Location
    Digged in further and the below formula works fine for dates within a month and its not working as expected if the dates between 2 months.

    =NETWORKDAYS(A2,B2,RDATA!$AC$2:$AC$71)-1&"\"&TEXT(B2-A2,"hh")&"\"&RIGHT(TEXT(B2-A2,"hh:mm"),2)
    Any help/ guidance is much awaited.

    Best
    Rem0

  6. #6
    VBAX Regular
    Joined
    Dec 2012
    Posts
    55
    Location
    Hi

    Any advice / guidance?

    Still stuck on this...

  7. #7
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    check this for calculating working hours:
    http://chandoo.org/wp/2010/09/10/working-hours-formula/

    you can download the workbook at the bottom of the page...
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  8. #8
    VBAX Regular
    Joined
    Dec 2012
    Posts
    55
    Location
    mancubus...Thanks

    I managed to custom the formula for my need, but still facing an issue with that.

    If you can take a look on the below link and advise that will be great.

    http://chandoo.org/wp/2010/09/10/wor...omment-1005705

  9. #9
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    what's that?
    i see nothing new there...
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  10. #10
    VBAX Regular
    Joined
    Dec 2012
    Posts
    55
    Location
    may be its still under moderation.

    here it is...

    I have managed to custom the formula and it works fine but it throws error for below start and end date (all GMT).

    Start: 21/06/2015 17:49

    End: 22/06/2015 06:55

    =TEXT((24*(NETWORKDAYS(A4,B4,RDATA!$AC$2:$AC$71)-1)-24*((MAX(MOD(A4,1),MOD(B4,1))-MIN(MOD(A4,1),MOD(B4,1)))))/24,”dd/hh/mm”)
    Not sure what the error is but will be helpful if you can point out anything in the formula.

  11. #11
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    i am not sure dd/hh/mm is a valid date/time format.
    second issue is, especially when you copy a formula from a web site, make sure special characters (such as single or double quotes) are valid excel characters...
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  12. #12
    VBAX Regular
    Joined
    Dec 2012
    Posts
    55
    Location
    Apologies!

    here you go...

    =TEXT((24*(NETWORKDAYS(A5,B5,RDATA!$AC$2:$AC$71)-1)-24*((MAX(MOD(A5,1),MOD(B5,1))-MIN(MOD(A5,1),MOD(B5,1)))))/24,"dd/hh/mm")
    for the dd/hh/mm have tested and works fine...

    if you can advise why the above formula fails for the date range given above will be great help...

  13. #13
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    see if this helps...
    http://answers.microsoft.com/en-us/o...deba755?auth=1

    as you can see i am just googling...
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  14. #14
    VBAX Regular
    Joined
    Dec 2012
    Posts
    55
    Location
    mancubus...

    managed to break thru...

    May be it might help others....


    =IF(AND(DAY(A2)<>DAY(B2),MONTH(A2)<>MONTH(B2),OR(MOD(A2,1)>MOD(B2,1),MOD(A2,1)<MOD(B2,1))),TEXT((24*(NETWORKDAYS(A2,B2,RDATA!$AC$2:$AC$71))-24*((MOD(A2,1)-MOD(B2,1))))/24-1,"d/hh/mm"),IF(AND(DAY(A2)<>DAY(B2),MONTH(A2)=MONTH(B2),MOD(A2,1)<MOD(B2,1)),TEXT((24*(NETWORKDAYS(A2,B2,RDATA!$AC$2:$AC$71))-24*((MOD(A2,1)-MOD(B2,1))))/24-1,"d/hh/mm"),IF(AND(DAY(A2)<>DAY(B2),MONTH(A2)=MONTH(B2),MOD(A2,1)>=MOD(B2,1),MAX(A2:B2)-MIN(A2:B2)>=6),NETWORKDAYS(A2,B2,RDATA!$AC$2:$AC$71)-IF(MOD(A2,1)<=MOD(B2,1),0,1)-1&"/"&TEXT(B2-A2,"hh")&"/"&RIGHT(TEXT(B2-A2,"hh:mm"),2),IF(AND(DAY(A2)<>DAY(B2),MONTH(A2)=MONTH(B2),MOD(A2,1)>MOD(B2,1),MAX(A2:B2)-MIN(A2:B2)<6),NETWORKDAYS(A2,B2,RDATA!$AC$2:$AC$71)-IF(MOD(A2,1)<=MOD(B2,1),0,1)&"/"&TEXT(B2-A2,"hh")&"/"&RIGHT(TEXT(B2-A2,"hh:mm"),2),IF(AND(DAY(A2)=DAY(B2),MONTH(A2)=MONTH(B2),MOD(A2,1)<MOD(B2,1)),NETWORKDAYS(A2,B2,RDATA!$AC$2:$AC$71)-IF(MOD(A2,1)<=MOD(B2,1),0,1)-1&"/"&TEXT(B2-A2,"hh")&"/"&RIGHT(TEXT(B2-A2,"hh:mm"),2),"")))))
    Best
    Rem0

  15. #15
    VBAX Regular
    Joined
    Dec 2012
    Posts
    55
    Location
    Note: The result shows as No. of Days / No. of hours / No. of Minutes....

    dd / hh / mm

  16. #16
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Thanks for posting the solution. This time I will use the Thread Tool menu to mark the thread Solved for you.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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