+ Reply to Thread
Results 1 to 14 of 14

subtracting dates

  1. #1
    Registered User
    Join Date
    08-09-2009
    Location
    New York, USA
    MS-Off Ver
    Excel 2003
    Posts
    17

    subtracting dates

    entry date exit date

    8-10-2009 10-5-09

    I need to know the difference between the exit day and the current month


    10Q in advance
    Last edited by galarza; 10-25-2009 at 04:56 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: subtracting dates

    In your example above, what do you expect the answer to be?

    The Exit Day and the current month are the same, so it's unclear.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    08-09-2009
    Location
    New York, USA
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: subtracting dates

    entry date exit days number of days

    9/21/2009 10/1/09
    9/22/2009 10/2/09
    9/28/2009 10/6/09
    10/2/2009 10/9/09
    10/2/2009 10/2/09
    10/3/2009 10/3/09
    10/5/2009 10/8/09
    10/5/2009
    10/5/2009
    10/5/2009

    Apologize for not been clear.

    I need to know how many days this person remained in the month of October

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: subtracting dates

    This formula is a bit of a trick. You put the month start date in a fixed cell (in this case C1), then use this SUMPRODUCT() formula:
    Please Login or Register  to view this content.
    In C2 use:
    =SUMPRODUCT((ROW(INDIRECT($A2&":"&$B2))>=$C$1) * (ROW(INDIRECT($A2&":"&$B2))<DATE(YEAR(C$1),MONTH(C$1)+1,1)))

    ...and copy it down.


    When adding/subtracting dates, people disagree about what the answer should be, some think the dates should be inclusive of the start date, other say no. That's why I asked you for some sample answers. Anyway, you may decide you need to subtract 1 from the answers. Up to you.

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: subtracting dates

    JB, why the need for (Volatile) SUMPRODUCT ?

    With month specified in C1

    =MIN(DATE(YEAR(C$1),MONTH(C$1)+1,0),B2+1)-MAX(C$1-DAY(C$1)+1,A2)
    copied down

    if you know categorically that C1 is always first of month you can remove the -DAY+1 check.

  6. #6
    Registered User
    Join Date
    08-09-2009
    Location
    New York, USA
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: subtracting dates

    numb of
    start end nights

    9/22/2009 10/2/09 1
    9/28/2009 10/6/09 5
    10/2/2009 10/9/09 7
    10/2/2009 10/2/09 0
    10/3/2009 10/3/09 0
    10/5/2009 10/8/09 3
    9/25/2009 10/6/09 5

    I should get this results. We count just nights, just like in a hotel billing, 10Q for you patience

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: subtracting dates

    As I said, then, my original formula... then -1.
    =SUMPRODUCT((ROW(INDIRECT($A2&":"&$B2))>=$C$1) * (ROW(INDIRECT($A2&":"&$B2))<DATE(YEAR(C$1),MONTH(C$1)+1,1))) - 1

    Or Don's.... -1:
    =MIN(DATE(YEAR(C$1),MONTH(C$1)+1,0),B2+1)-MAX(C$1-DAY(C$1)+1,A2) - 1

    ===========
    If that takes care of your need, be sure to EDIT your original post, click Go Advanced and mark the PREFIX box [SOLVED].


    (Also, use the blue "scales" icon in our posts to leave Reputation Feedback, it is appreciated)

  8. #8
    Registered User
    Join Date
    08-09-2009
    Location
    New York, USA
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: subtracting dates

    Thanks you guys are great, 10Q as always

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: subtracting dates

    If that takes care of your need, be sure to EDIT your original post, click Go Advanced and mark the PREFIX box [SOLVED].


    (Also, use the blue "scales" icon in our posts to leave Reputation Feedback, it is appreciated)

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

    Re: subtracting dates

    Quote Originally Posted by JBeaucaire View Post
    =MIN(DATE(YEAR(C$1),MONTH(C$1)+1,0),B2+1)-MAX(C$1-DAY(C$1)+1,A2) - 1
    That won't give the correct results in all circumstances, try making B2 31st October......

    This should work better

    =MIN(DATE(YEAR(C$1),MONTH(C$1)+1,1),B2)-MAX(C$1-DAY(C$1)+1,A2)

    although you might want to adjust that to take account of end dates that are eralier than the current month, i.e.

    =MAX(0,MIN(DATE(YEAR(C$1),MONTH(C$1)+1,1),B2)-MAX(C$1-DAY(C$1)+1,A2))

  11. #11
    Registered User
    Join Date
    08-09-2009
    Location
    New York, USA
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: subtracting dates

    Ooops one more thing, how can I get rid of the negative numbers??, since I need to run a total at the end of the sheet??


    12
    27
    -40087
    -40087
    -40087
    1
    -40087
    7
    1
    0
    15
    -40087

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

    Re: subtracting dates

    Quote Originally Posted by daddylonglegs View Post
    =MAX(0,MIN(DATE(YEAR(C$1),MONTH(C$1)+1,1),B2)-MAX(C$1-DAY(C$1)+1,A2))
    See my suggestion above.....

  13. #13
    Registered User
    Join Date
    08-09-2009
    Location
    New York, USA
    MS-Off Ver
    Excel 2003
    Posts
    17

    Angry Re: subtracting dates

    I tried the =min and =max formulas and I get 31 when I fill them down.

  14. #14
    Registered User
    Join Date
    08-09-2009
    Location
    New York, USA
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: subtracting dates

    Quote Originally Posted by daddylonglegs View Post
    See my suggestion above.....
    I tried the =min and =max formulas and I get 31 when I fill them down.

+ 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