+ Reply to Thread
Results 1 to 16 of 16

Calculate difference between dates excluding weekends

  1. #1
    Registered User
    Join Date
    05-22-2008
    Posts
    19

    Calculate difference between dates excluding weekends

    Hi there
    I would like to know how i can calculate the difference (in days) between two dates, excluding the weekends from the calculation.
    For example lets say A1 has 22 May 2008 and A2 has 27 May 2008. How do i calculate the difference between A2 and A1 so i get the answer as 3. Using Networkdates gives me 4 (it includes the start date in the calculation). I can't use datedif because sometimes my first date is smaller than the second date, in which case it gives me an error.
    Also, occasionally my two dates are from two different years like it can be 22 May 2007 and 27 May 2008.
    It would be really helpful if someone can help with this.
    Many Thanks in advance
    Cheers
    Nitin
    Last edited by nitinjoshi123; 05-23-2008 at 12:19 AM.

  2. #2
    Forum Contributor EdMac's Avatar
    Join Date
    01-23-2006
    Location
    Exeter, UK
    MS-Off Ver
    2003
    Posts
    1,264
    try this - it does not matter which is the smaller date

    Please Login or Register  to view this content.
    Ed
    _____________________________
    Always learning, but never enough!
    _____________________________

  3. #3
    Forum Expert oldchippy's Avatar
    Join Date
    02-14-2005
    Location
    Worcester, UK
    MS-Off Ver
    Excel 2007 (Home)
    Posts
    7,097
    If you haven't got the Analysis Tool-Pak installed for NETWORKDAYS, here's an alternative

    Please Login or Register  to view this content.
    oldchippy
    -------------


    Blessed are those who can give without remembering and take without forgetting

    If you are happy with the help you have received, please click the <--- STAR icon on the left - Thanks.

    Click here >>> Top Excel links for beginners to Experts

    Forum Rules >>>Please don't forget to read these

  4. #4
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    Is it possible for the start date to be a Saturday or Sunday, in which case what result do you expect, e.g. for start date 17-May-2008 end date 20-May-2008?

  5. #5
    Registered User
    Join Date
    05-22-2008
    Posts
    19
    Hi
    Yes!!! the start date can be Saturday or Sunday....
    Thanks
    Nitin
    Last edited by nitinjoshi123; 05-25-2008 at 05:41 PM.

  6. #6
    Registered User
    Join Date
    05-22-2008
    Posts
    19

    Smile

    HI EDMAC
    This solution doesn't work if the second date is smaller than the first date. I need the negative values as well. Also, when the second date is smaller, -1 adds one more to the difference.
    For example: lets take the start date as 26 may 2008
    If the second date is 29 May, i need 3 as an answer
    If the second date is 3 June, i need 6 as an answer
    If the second date is 19 May, i need -5 as an answer
    Please advice...
    Thanks a lot
    Cheers
    Nitin

  7. #7
    Forum Expert oldchippy's Avatar
    Join Date
    02-14-2005
    Location
    Worcester, UK
    MS-Off Ver
    Excel 2007 (Home)
    Posts
    7,097
    Hi,

    Try this,

    =IF(A1<=B1,NETWORKDAYS(A1,B1)-1,NETWORKDAYS(A1,B1)+1)

  8. #8
    Registered User
    Join Date
    05-22-2008
    Posts
    19
    HI OldChippy
    Thanks!!! but this is not working if the first date is weekend

  9. #9
    Registered User
    Join Date
    05-22-2008
    Posts
    19

    USING NETWORKDAYS if the start date is saturday

    Hi
    I wanna calculate the difference between two dates, excluding the weekends. Networkdays works fine, but the answer is corrupted if the start date is a saturday.
    My start date is sometime smaller than the last date, in which case the answer should be negative.
    Many many thanks in advance
    Nits

  10. #10
    Forum Expert oldchippy's Avatar
    Join Date
    02-14-2005
    Location
    Worcester, UK
    MS-Off Ver
    Excel 2007 (Home)
    Posts
    7,097
    Hi,

    If the start date falls on a Saturday or Sunday, do you want to calculate from the Friday or the Monday?

    Same applies with the end date?

  11. #11
    Forum Contributor EdMac's Avatar
    Join Date
    01-23-2006
    Location
    Exeter, UK
    MS-Off Ver
    2003
    Posts
    1,264
    If the second date is 29 May, i need 3 as an answer
    If the second date is 3 June, i need 6 as an answer
    If the second date is 19 May, i need -5 as an answer
    This gives the answers you require

    Please Login or Register  to view this content.
    HTH

  12. #12
    Registered User
    Join Date
    05-22-2008
    Posts
    19
    Hi OldChippy
    If the start date is saturday or sunday, i want to start from Monday. Similarly if the end date is saturday or sunday, i want to calculate upto Friday.
    Thanks
    Nitin

  13. #13
    Registered User
    Join Date
    05-22-2008
    Posts
    19
    Quote Originally Posted by EdMac
    This gives the answers you require

    Please Login or Register  to view this content.
    HTH
    HI Edmac
    Itried this but it is giving me name error

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

    I think I have an idea what you want to do but it helps if you can give specific representative examples, the only examples you gave have weekdays as both start and end date.

    Given that you say that this formula suggested by oldchippy gives incorrect results when start date is at the weekend

    =IF(A1<=B1,NETWORKDAYS(A1,B1)-1,NETWORKDAYS(A1,B1)+1)

    ...then I assume that if start date is Saturday and end date is 3 days later that result should be 2. For that try

    =NETWORKDAYS(A1,B1)+IF(NETWORKDAYS(A1,A1)+ NETWORKDAYS(B1,B1)=2,-SIGN(NETWORKDAYS(A1,B1)),0)

  15. #15
    Registered User
    Join Date
    05-22-2008
    Posts
    19
    Hi Daddylonglegs
    Fantastic!!! thanks!! it worked for me..
    There is one glitch however.
    If my start date is 23/05/08 (Friday) and the end date is 30/05/08 (Friday), the answer is 5, which is correct. Howver, if my start date is 23/05/08 (Friday) and my last date is 31/05/08 (Saturday), the answer it is giving is 6, when it should be 5.
    Any suggestions!!!!
    Thanks

  16. #16
    Registered User
    Join Date
    05-22-2008
    Posts
    19
    Giving me trouble again. I used the formula in my actual sheet and it is givingh me 2 as an anwer for start date 23/04/2008 and end date 24/04/2008, when it actually should be one.
    Any suggestions

+ 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