+ Reply to Thread
Results 1 to 30 of 30

Calculating number of days from todays date

  1. #1
    Registered User
    Join Date
    11-06-2015
    Location
    manchester
    MS-Off Ver
    2010
    Posts
    15

    Calculating number of days from todays date

    Hi
    Sorry if this has been asked before, cant find the exact answer anywhere.
    Im trying to set up a spreadsheet which will calculate the number of days a procedure is done in relation to todays date.
    For example if the procedure was on 5th November today I would like the cell to read D+1.
    If the procedure is due to be done on 7th November the cell would read D-1.
    (and if the procedure was done today it would say D0)

    Hope this doesnt sound too complex? Will be very grateful if someone can figure this out for me!
    thanks
    Joe

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Calculating number of days from todays date

    Hi Joe,

    Here's a function:

    Please Login or Register  to view this content.
    If you haven't used macros before you'll need to go to:
    File- options - trust center -trust center settings - macro settings ,
    the second option down (disable all macros with notification)

    Then - Copy the code to the clipboard

    Open your Workbook

    Press ALT + F11 to open the Visual Basic Editor.

    Select "Module" from the Insert menu

    Type "Option Explicit" then paste the code under it

    Then you can invoke just like a regular Worksheet Function i.e.Data Range
    A
    B
    10
    30-Nov
    D+24
    where
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    is the entry in B10

    And Welcome to the Forum!
    Last edited by xladept; 11-06-2015 at 04:33 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    11-06-2015
    Location
    manchester
    MS-Off Ver
    2010
    Posts
    15

    Re: Calculating number of days from todays date

    Hey thanks for the quick reply! Thats genius. It works but I need to adjust it as its calculating the wrong way round eg when i put 7th nov it says D+1 when it should be d-1?
    any idea how i can make it the inverse?
    thanks

  4. #4
    Forum Contributor Obsessed's Avatar
    Join Date
    05-22-2013
    Location
    Cincinnati, Ohio
    MS-Off Ver
    Excel 365
    Posts
    215

    Re: Calculating number of days from todays date

    I think this gives you what you want, and is a bit simpler:

    =CONCATENATE("D"&IF((TODAY()-A2)>0,"+","")&TODAY()-A2)

    Put in B2, looks at A2. Modify as needed.

    DateDifference.JPG
    Want to show appreciation for the help you received from a member? Give them reps by clicking the bottom left of their post!

  5. #5
    Registered User
    Join Date
    11-06-2015
    Location
    manchester
    MS-Off Ver
    2010
    Posts
    15

    Re: Calculating number of days from todays date

    THanks that also works but again its the wrong way round and if i put tomorrows date it says D+1 when i want D-1?

  6. #6
    Forum Contributor Obsessed's Avatar
    Join Date
    05-22-2013
    Location
    Cincinnati, Ohio
    MS-Off Ver
    Excel 365
    Posts
    215

    Re: Calculating number of days from todays date

    Um...is your computer date correct? Check out my screenshot...it's exactly what you want.

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Calculating number of days from todays date

    I just switched the signs

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    11-06-2015
    Location
    manchester
    MS-Off Ver
    2010
    Posts
    15

    Re: Calculating number of days from todays date

    Thanks alot! this forum is amazing...trying to set up a spreadsheet for a bone marrow transplant unit so will probably have more questions soon!

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Calculating number of days from todays date

    You're welcome, under the circumstance, especially so!

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Calculating number of days from todays date

    It wasn't right:

    Please Login or Register  to view this content.
    Should be correct now - let me know

  11. #11
    Forum Contributor Obsessed's Avatar
    Join Date
    05-22-2013
    Location
    Cincinnati, Ohio
    MS-Off Ver
    Excel 365
    Posts
    215

    Re: Calculating number of days from todays date

    Heh, still wish I knew why mine isn't working for OP...xladept, any ideas?

  12. #12
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Calculating number of days from todays date

    Hi Obsessed,

    Your formula works for me

    Maybe the OP prefers D-0 to D0

  13. #13
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Calculating number of days from todays date

    Hi Obsessed, your formula works just fine. You don't however need to surround the formula with the CONCATENATE. This will produce the same result.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    If you really want to shorten it this will also work"
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Those are much better than this just for the sake of a "-"
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  14. #14
    Registered User
    Join Date
    11-06-2015
    Location
    manchester
    MS-Off Ver
    2010
    Posts
    15

    Re: Calculating number of days from todays date

    Thanks still having problems with both methods.
    AS the days are still wrong way round to clarify if I put yesterdays date I want it to say D+1 not D-1 ?
    Also do you know how I can make it the case that if i leave the cell blank (no date) that the cell that calulates the day remains blank? as it currently says D+149553 if i leave the date blank?
    thanks!

  15. #15
    Registered User
    Join Date
    11-06-2015
    Location
    manchester
    MS-Off Ver
    2010
    Posts
    15

    Re: Calculating number of days from todays date

    Im making this alot more complex than it should be! but now I have tried changing the + and - signs round on visual basic editor and now whenever i clinic the cell to write the date i get an error msg saying ambiguous name detected: DoneDate
    Is this because ive entered more than one command for this?

    Does anyone know how i can start again without starting opening a new workbook as already have the table set up now

  16. #16
    Forum Contributor Obsessed's Avatar
    Join Date
    05-22-2013
    Location
    Cincinnati, Ohio
    MS-Off Ver
    Excel 365
    Posts
    215

    Re: Calculating number of days from todays date

    Try putting something like, 7 days out and see what it says. I find it odd that it works for everyone but you.

  17. #17
    Forum Contributor Obsessed's Avatar
    Join Date
    05-22-2013
    Location
    Cincinnati, Ohio
    MS-Off Ver
    Excel 365
    Posts
    215

    Re: Calculating number of days from todays date

    Quote Originally Posted by newdoverman View Post
    Hi Obsessed, your formula works just fine. You don't however need to surround the formula with the CONCATENATE. This will produce the same result.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Yeah, I know about that, but I prefer the Concatenate wording...it helps explain to newer people what it's doing. In practice I personally have never found a need for it though.
    Last edited by Obsessed; 11-07-2015 at 03:44 PM.

  18. #18
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Calculating number of days from todays date

    I don't know why you are getting the wrong answers unless your computer date is wrong. This is the result from my computer using
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    all the other formulae return the same result except for D-0 being D0.

    A
    B
    C
    2
    05/11/2015
    D+2
    3
    06/11/2015
    D+1
    4
    07/11/2015
    D-0 today
    5
    08/11/2015
    D-1
    6
    09/11/2015
    D-2
    7
    10/11/2015
    D-3
    8
    11/11/2015
    D-4
    9
    12/11/2015
    D-5
    10
    13/11/2015
    D-6
    11
    14/11/2015
    D-7
    12
    15/11/2015
    D-8
    13
    16/11/2015
    D-9
    14
    17/11/2015
    D-10
    15
    18/11/2015
    D-11
    16
    19/11/2015
    D-12
    17
    18
    ="D"&IF(TODAY()>A2,"+"&TODAY()-A2,IF(TODAY()<A2,(A2-TODAY())*-1,"-0"))

  19. #19
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Calculating number of days from todays date

    Hi Joesiv,

    You can only have one function named DoneDate - so delete all but the last version

  20. #20
    Registered User
    Join Date
    11-06-2015
    Location
    manchester
    MS-Off Ver
    2010
    Posts
    15

    Re: Calculating number of days from todays date

    Thanks the + /- is the correct way around now.
    Does anyone know how I can get it to be blank when I remove a date from the cell (currently when I delete the date the cell which works out the funciton will say D+1439 (or another equally long number)

  21. #21
    Forum Contributor Obsessed's Avatar
    Join Date
    05-22-2013
    Location
    Cincinnati, Ohio
    MS-Off Ver
    Excel 365
    Posts
    215

    Re: Calculating number of days from todays date

    What formula are you currently using? Or are you using xladept's function?

  22. #22
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Calculating number of days from todays date

    Another version:

    Please Login or Register  to view this content.

  23. #23
    Registered User
    Join Date
    11-06-2015
    Location
    manchester
    MS-Off Ver
    2010
    Posts
    15

    Re: Calculating number of days from todays date

    Thanks xladept! that one is perfect!
    Would you mind sending me another one too?
    I need another one similar to above without - and + signs and starting at D1 instead of 0
    example for todays date it would read D1 and for tomorrow D2 (no minus numbers needed)

    (and would I call this function a different name as I would want to use this one for some patients and the DoneDate for others?)

  24. #24
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Calculating number of days from todays date

    Try this:

    Please Login or Register  to view this content.

  25. #25
    Registered User
    Join Date
    11-06-2015
    Location
    manchester
    MS-Off Ver
    2010
    Posts
    15

    Re: Calculating number of days from todays date

    Works a treat! thanks very much!

  26. #26
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Calculating number of days from todays date

    You're welcome and thanks for the rep!

  27. #27
    Registered User
    Join Date
    11-06-2015
    Location
    manchester
    MS-Off Ver
    2010
    Posts
    15

    Re: Calculating number of days from todays date

    Sorry xlad the second formula is wrong (as i gave you the wrong info)
    I want it for todays date to read D1 and for yesterdays date to read D2 (if I put a future date i want it to remain blank)
    Sorry :S

  28. #28
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Calculating number of days from todays date

    Please Login or Register  to view this content.

  29. #29
    Registered User
    Join Date
    11-06-2015
    Location
    manchester
    MS-Off Ver
    2010
    Posts
    15

    Re: Calculating number of days from todays date

    thanks again!

  30. #30
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Calculating number of days from todays date

    Welcome again!

+ 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. Replies: 10
    Last Post: 02-19-2019, 03:28 AM
  2. Autohide Columns that are < todays date and > todays date by 2 & 7 days
    By Dropfiddy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-28-2015, 03:51 AM
  3. excel formula: days remaining=end date-todays date+extention days
    By fsprings in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 01-04-2013, 06:45 AM
  4. Replies: 3
    Last Post: 02-05-2012, 01:32 PM
  5. Todays date + 28 days + 2 week days
    By tubbsy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-18-2008, 12:39 PM
  6. Calculating Number of days from one date to another
    By Renz09 in forum Excel General
    Replies: 2
    Last Post: 05-03-2006, 05:20 AM
  7. [SOLVED] Number of days between 2 dates, if end date is blank assume todays
    By JulesM in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 03-01-2006, 08:45 AM

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