+ Reply to Thread
Results 1 to 15 of 15

From number of days to Years, months and days DATEDIFF madness!!

  1. #1
    Registered User
    Join Date
    12-30-2020
    Location
    london, england
    MS-Off Ver
    2016
    Posts
    13

    From number of days to Years, months and days DATEDIFF madness!!

    Hi Everybody,

    I have this great little sheet doing some calculations with VBA and excel formulas. All is well until I decided to convert the resulting days into yers months and days..

    =DATEDIF(0,3675,"y") & " years, " & DATEDIF(0,3675,"ym")&" months, " & DATEDIF(0,3675,"md")&" days"

    And the result is below...all look great right....NO!!!! its supposed to be 25 days not 22!!!
    10 years, 0 months, 22 days
    (the 3675 above comes from a cell D35)

    I've checked with various calculators on google and the resulting days should be 25

    Can anyone please help me keep some of my hair....

    Much appreciated

  2. #2
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,908

    Re: From number of days to Years, months and days DATEDIFF madness!!

    The leap years are: 1900,1904,1908 so there are only 22 days, not 25

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: From number of days to Years, months and days DATEDIFF madness!!

    if you format 0 as a date then excel returns 00/01/1900 which is obviously wrong but it is what it is.

    if you format 3675 as a date then excel returns 22/01/1910

    So 22 Days, 0 Months and 10 years.



    So what were you trying to calculate?
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  4. #4
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,463

    Re: From number of days to Years, months and days DATEDIFF madness!!

    If a year suppose to 365 days
    3675/365 = 365*10 + 25
    gives 10 years and 25 days. Is it are you looking for?
    Quang PT

  5. #5
    Registered User
    Join Date
    12-30-2020
    Location
    london, england
    MS-Off Ver
    2016
    Posts
    13

    Re: From number of days to Years, months and days DATEDIFF madness!!

    sorry guys totally my mistake i used a solution I found online for the converting of days (as in a date) to years, months and days

    that's totally wrong. What I really wanted to use is a formula that takes a number of days (not as in a date from 1900) and then displays a year, month and day result as in below..

    now im trying to get the years months and days separated..hmmm any suggestion how to do that..

    years is pretty simple I can round that to whole numbers but months/days is trickier...

    365/12 = 30.416

    3675 days / 30.416 = 120.8246 months

    that's 10 full years and 0 months and 0.8246 days

    then to get the 0.8246 x 30.416 is 25.08 rounded down to 25 days

    my brain is starting to melt slightly...how do I get the months and then all into a formula....? input days then display 10, 0, 25 in a cell

  6. #6
    Registered User
    Join Date
    12-30-2020
    Location
    london, england
    MS-Off Ver
    2016
    Posts
    13

    Re: From number of days to Years, months and days DATEDIFF madness!!

    Quote Originally Posted by bebo021999 View Post
    If a year suppose to 365 days
    3675/365 = 365*10 + 25
    gives 10 years and 25 days. Is it are you looking for?
    hahaha yes! I'm pretty daft sometimes.... so how would I get the months separated if lets say its 3775 days

    meaning how would I construct a formula that checks for full years and then months and then days...months wold have to be 30 days I guess...or 365/12=30.41667
    Last edited by zozew; 01-13-2021 at 09:55 PM.

  7. #7
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: From number of days to Years, months and days DATEDIFF madness!!

    Ok

    Step back a bit. Each Month and Year may have different numbers of years So....

    3775 Days After what date?

    3775 Days Before what date?



    =DATEDIF(TODAY(),TODAY()+3675,"y") & " years, " & DATEDIF(TODAY(),TODAY()+3675,"ym")&" months, " & DATEDIF(TODAY(),TODAY()+3675,"md")&" days"
    Returns
    10 years, 0 months, 23 days


    =DATEDIF(TODAY()-3675,TODAY(),"y") & " years, " & DATEDIF(TODAY()-3675,TODAY(),"ym")&" months, " & DATEDIF(TODAY()-3675,TODAY(),"md")&" days"
    Returns
    10 years, 0 months, 22 days
    Last edited by mehmetcik; 01-13-2021 at 10:20 PM.

  8. #8
    Registered User
    Join Date
    12-30-2020
    Location
    london, england
    MS-Off Ver
    2016
    Posts
    13

    Re: From number of days to Years, months and days DATEDIFF madness!!

    Hi,

    so the days are not connected to any date...

    it could be 65 days or 10657 days...i just want them converted into years months and days something like

    8 years, 4 months, 6days

    for example:

    I have 10657 days how many years months and days is that

    10657/365=29 full years and 72 days

    72/(365/12)= 2.36712329 so 2 full months and (365/12)*0.36712329 remaining days

    (365/12)*0.36712329 = 8.933333334 so that's 9 days rounded up

    result is

    29 years, 2 months, 9 days

    my question is how do I make a formula out of that...
    Last edited by zozew; 01-13-2021 at 10:35 PM.

  9. #9
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,463

    Re: From number of days to Years, months and days DATEDIFF madness!!

    It seems 365 days/year, 30 days/month ?

    If A1 = 3775

    Year =INT(A1/365) = 10
    Month = =INT(MOD(A1,365)/30) = 4
    Days =MOD(MOD(A1,365),30) = 5

    test: 10*365+4*30+5 = 3775

    Combine them with "years", "months" and "days"

  10. #10
    Registered User
    Join Date
    12-30-2020
    Location
    london, england
    MS-Off Ver
    2016
    Posts
    13

    Re: From number of days to Years, months and days DATEDIFF madness!!

    Great Thanks!

    Ill try your formulas

    im using 365/12 as days per month

    I'm testing this now

    year = INT((A1/365))
    Month =INT((((A1/365)-TRUNC((A1/365)))*365)/(365/12))
    day =ROUND((((((((A1/365)-TRUNC((A1/365)))*365)/(365/12))-TRUNC(((((A1/365)-TRUNC((A1/365)))*365)/(365/12))))))*(365/12),0)

    I know it looks ridiculous but it seems to work

  11. #11
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: From number of days to Years, months and days DATEDIFF madness!!

    Not Possible. Choose a date as a reference. like in your original post you used 0. try using 1.

    Then all your calculations will be based on 01/01/1900 and you will get consistent results.

    =DATEDIF(1,3675,"y") & " years, " & DATEDIF(1,3675,"ym")&" months, " & DATEDIF(1,3675,"md")&" days"

  12. #12
    Registered User
    Join Date
    12-30-2020
    Location
    london, england
    MS-Off Ver
    2016
    Posts
    13

    Re: From number of days to Years, months and days DATEDIFF madness!!

    Quote Originally Posted by bebo021999 View Post
    It seems 365 days/year, 30 days/month ?

    If A1 = 3775

    Year =INT(A1/365) = 10
    Month = =INT(MOD(A1,365)/30) = 4
    Days =MOD(MOD(A1,365),30) = 5

    test: 10*365+4*30+5 = 3775

    Combine them with "years", "months" and "days"
    your solution gives exactly the same result as mine...just that yours is much easier to read hahaha thanks

  13. #13
    Registered User
    Join Date
    12-30-2020
    Location
    london, england
    MS-Off Ver
    2016
    Posts
    13

    Re: From number of days to Years, months and days DATEDIFF madness!!

    Quote Originally Posted by mehmetcik View Post
    Not Possible. Choose a date as a reference. like in your original post you used 0. try using 1.

    Then all your calculations will be based on 01/01/1900 and you will get consistent results.

    =DATEDIF(1,3675,"y") & " years, " & DATEDIF(1,3675,"ym")&" months, " & DATEDIF(1,3675,"md")&" days"
    hi, thanks for the suggestion but the solution from bebo021999 is the type I was looking for

    cheers!

  14. #14
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,463

    Re: From number of days to Years, months and days DATEDIFF madness!!

    zozew, to get number of days, months, years, normally using DATEDIF, with 365/366 days/year, 28,29,30,31 days/months are counted.

    In this case, years and months are fixed to 365 days and 12 months/year

    Therefore, my solution in #9 is an option.

    Your formula in #10 works for years and months, but for days, it does not.
    Days is alway interger, if you have to round it, it is not correct.
    test with 10657, your formula gives 11 that is not correct. (29*365+2*60+11=10656)

  15. #15
    Registered User
    Join Date
    12-30-2020
    Location
    london, england
    MS-Off Ver
    2016
    Posts
    13

    Re: From number of days to Years, months and days DATEDIFF madness!!

    Quote Originally Posted by bebo021999 View Post
    zozew, to get number of days, months, years, normally using DATEDIF, with 365/366 days/year, 28,29,30,31 days/months are counted.

    In this case, years and months are fixed to 365 days and 12 months/year

    Therefore, my solution in #9 is an option.

    Your formula in #10 works for years and months, but for days, it does not.
    Days is alway interger, if you have to round it, it is not correct.
    test with 10657, your formula gives 11 that is not correct. (29*365+2*60+11=10656)
    You are totally correct! but for my purposes this is totally acceptable I am using your formulas changing the months to 365/12 and it works great
    Last edited by zozew; 01-13-2021 at 11:02 PM.

+ 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. [SOLVED] Calculating Years, Months, Week, Days, Hours, Minutes for Work Days between two dates
    By hecgroups in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 08-23-2019, 12:09 AM
  2. [SOLVED] Convert number to years, months and days
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-14-2015, 01:47 PM
  3. How do I convert years, months, days back to complete days
    By Nisha Dhawan in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-13-2014, 03:21 AM
  4. Convert days -> Years, Months, Days, Hours, Minutes, Seconds
    By brharrii in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-06-2012, 06:44 PM
  5. [SOLVED] Number of years, months, days between two dates.
    By Bluenose in forum Excel Formulas & Functions
    Replies: 69
    Last Post: 06-01-2009, 02:55 PM
  6. [SOLVED] Number of years/months/days between 2 dates
    By Deborah in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-07-2006, 06:30 AM
  7. [SOLVED] Converting number of days to years and months
    By Dave Cobb in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-24-2005, 05:06 PM

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