+ Reply to Thread
Results 1 to 15 of 15

How to find the difference between two dates, and display it as (**y ***d)

  1. #1
    Registered User
    Join Date
    10-26-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2016
    Posts
    56

    How to find the difference between two dates, and display it as (**y ***d)

    Hello, is there a way to do this in one cell? For example I have two dates which I want to calculate the days between: 23/07/2012 and 16/11/2014.

    Subtracting the later date from the earlier date gives me 846 days, is there a way that I could then format this to show the result as "2y 116d"?

    The only way I can imagine with my excel skills is to create a column for Years, and a column for Days, subtracting X years * 365. Even with that process it will not work due to leap years occurring, and it would be ugly to have them in 2 separate columns. Does anybody have any ideas on this one?

    Thanks!

  2. #2
    Valued Forum Contributor
    Join Date
    02-05-2013
    Location
    Jakarta, Indonesia
    MS-Off Ver
    Excel 2013
    Posts
    571

    Re: How to find the difference between two dates, and display it as (**y ***d)

    Read this:
    Supressing Zero Value Components
    http://www.cpearson.com/excel/datedif.aspx
    Click (*) if you received helpful response.

    Regards,
    David

  3. #3
    Registered User
    Join Date
    10-26-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2016
    Posts
    56

    Re: How to find the difference between two dates, and display it as (**y ***d)

    Thank you, that link is great, I'd never heard of DatedIF before. However it doesn't seem to be working correctly..

    I have the two dates listed in my previous post, and the formula returns 2y 115d which seems correct, however I've put the date I was born in and today's date, and it's showing 55d. My birthday is this month so it should show 335+ days. Could this be the reason it is not documented, because it is buggy?

    This is the formula I am using:

    =DATEDIF(A1,B1,"y")&"y "&DATEDIF(A1,B1,"yd")&"d "

  4. #4
    Valued Forum Contributor
    Join Date
    02-05-2013
    Location
    Jakarta, Indonesia
    MS-Off Ver
    Excel 2013
    Posts
    571

    Re: How to find the difference between two dates, and display it as (**y ***d)

    Did you read this part and try it?

    Calculating Age
    You can use the DATEDIF to calculate a person's age. For example, the formula below will calculate the age of a person as of the current date, where BirthDate is the person's date of birth.
    =DATEDIF(BirthDate,TODAY(),"y")&" years "&DATEDIF(BirthDate,TODAY(),"ym")&" months "&DATEDIF(BirthDate,TODAY(),"md")&" days"

    Note: Because you not upload the example, I can't check your calculation.

  5. #5
    Valued Forum Contributor
    Join Date
    02-05-2013
    Location
    Jakarta, Indonesia
    MS-Off Ver
    Excel 2013
    Posts
    571

    Re: How to find the difference between two dates, and display it as (**y ***d)

    Sorry, may be your calculation not correct because the leap year as explain on this part "DATEDIF And Leap Years"

  6. #6
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: How to find the difference between two dates, and display it as (**y ***d)

    Alternatively you can use

    Please Login or Register  to view this content.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  7. #7
    Registered User
    Join Date
    10-26-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2016
    Posts
    56

    Re: How to find the difference between two dates, and display it as (**y ***d)

    Quote Originally Posted by SDCh View Post
    =DATEDIF(BirthDate,TODAY(),"y")&" years "&DATEDIF(BirthDate,TODAY(),"ym")&" months "&DATEDIF(BirthDate,TODAY(),"md")&" days"
    I did try this already and I got a #REF! error but I really can't figure out why.

    Quote Originally Posted by sktneer View Post
    Alternatively you can use

    Please Login or Register  to view this content.
    This one almost works, however it adds in separately all the leap years I have lived through, making me 24y 6d on my upcoming birthday.


    I have attached a sample sheet to show my formulas. My original dates in this thread are showing up perfectly, but with the same formula my age isn't. I am truly baffled here.


    EDIT: I've just noticed that if you change the date in B3 to 01/02/2014, it shows 1y 190d. If you change it to 01/05/2014, it also shows 1y 190d. I really think this function doesn't work.. Or maybe my formula is somehow wrong?
    Attached Files Attached Files
    Last edited by PistachioPedro; 11-01-2013 at 12:39 PM.

  8. #8
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,049

    Re: How to find the difference between two dates, and display it as (**y ***d)

    With your 1st (earlier) date in A1 and the later date in B1, try this...

    =IF(DATEDIF(A1,B1,"y")=0,"",DATEDIF(A1,B1,"y")&" years ")&IF(DATEDIF(A1,B1,"ym")=0,"",DATEDIF(A1,B1,"ym")&" months ")&DATEDIF(A1,B1,"md")&" days"
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  9. #9
    Registered User
    Join Date
    10-26-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2016
    Posts
    56

    Re: How to find the difference between two dates, and display it as (**y ***d)

    FDibbins, thank you, that works however I'm wanting to eliminate the months. I would like it to only count the years and days.

  10. #10
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: How to find the difference between two dates, and display it as (**y ***d)

    More precisely you can use this too......

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    10-26-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2016
    Posts
    56

    Re: How to find the difference between two dates, and display it as (**y ***d)

    Ahhh! Thank you so much, this revision works perfectly.

  12. #12
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,049

    Re: How to find the difference between two dates, and display it as (**y ***d)

    Ok try this then...
    =IF(DATEDIF(A1,B1,"y")=0,"",DATEDIF(A1,B1,"y")&" years ")&DATEDIF(A1,B1,"yd")&" days"

  13. #13
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: How to find the difference between two dates, and display it as (**y ***d)

    Glad to help you. Thanks for the feedback.

  14. #14
    Registered User
    Join Date
    10-26-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2016
    Posts
    56

    Re: How to find the difference between two dates, and display it as (**y ***d)

    Quote Originally Posted by FDibbins View Post
    Ok try this then...
    =IF(DATEDIF(A1,B1,"y")=0,"",DATEDIF(A1,B1,"y")&" years ")&DATEDIF(A1,B1,"yd")&" days"
    This one gave me the exact same result as I had posted I was using. I am convinced that DATEDIF is poorly coded or something and that's why it's not used. It seems to work when you use the year and month portion, but not the days portion.

  15. #15
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,049

    Re: How to find the difference between two dates, and display it as (**y ***d)

    A21=7/23/2012
    A22= 11/16/2014
    2 years 116 days
    =IF(DATEDIF(A21,A22,"y")=0,"",DATEDIF(A21,A22,"y")&" years ")&DATEDIF(A21,A22,"yd")&" days"

+ 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. How to find the difference between 2 dates in days
    By nav505 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-11-2013, 07:45 AM
  2. To find difference between dates
    By Bhawna in forum Excel General
    Replies: 2
    Last Post: 08-08-2012, 10:07 AM
  3. Replies: 5
    Last Post: 11-09-2011, 01:01 PM
  4. Find the difference between dates
    By SMB618 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-05-2010, 01:43 PM
  5. Display difference in 2 dates as xx.xx?
    By Ltat42a in forum Excel General
    Replies: 1
    Last Post: 03-08-2009, 09:35 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