+ Reply to Thread
Results 1 to 5 of 5

Calculate Years, Months Weeks

  1. #1
    Valued Forum Contributor
    Join Date
    07-16-2007
    Location
    GA
    MS-Off Ver
    Office 365 - Version 2403
    Posts
    1,054

    Calculate Years, Months Weeks

    Hi,

    I have a formula that can calculate the difference between two dates & give me a result like:


    # Years(s), # Month(s)

    # = Number or result difference between dates.


    Here's the formula I'm using to get above results:

    =IF(S11="","0 Years(s), 0 Month(s), 0 Day(s)",IF(S14="TBD",DATEDIF(S11,TODAY(),"y")&" year(s), "&DATEDIF(S11,TODAY(),"ym")&" month(s)",IF(S14>1,DATEDIF(S11,S14,"y")&" year(s), "&DATEDIF(S11,S14,"ym")&" month(s) ")))


    Now, I would like to add in Weeks, but not certain what the "week" code is to give:


    # Years(s), # Month(s), # Week(s)




    =IF(S11="","0 Years(s), 0 Month(s), 0 Day(s)",IF(S14="TBD",DATEDIF(S11,TODAY(),"y")&" year(s), "&DATEDIF(S11,TODAY(),"ym")&" month(s)",IF(S14>1,DATEDIF(S11,S14,"y")&" year(s), "&DATEDIF(S11,S14,"ym")&" month(s) "&DATEDIF(S11,S14,"mw")&" Week(s) ")))


    This, "mw" is wrong n my formula to find or calculate weeks. What should be here or is there a better way to calculate the difference between two dates & still get:

    # Years(s), # Month(s), # Week(s)

    Thanks
    MyCon
    -- Using Latest Version of Excel

  2. #2
    Forum Expert
    Join Date
    12-03-2009
    Location
    Florence, Italy
    MS-Off Ver
    Excel 2019
    Posts
    1,796

    Re: Calculate Years, Months Weeks

    Hi, a possibility

    Number of weeks:

    =INT(DATEDIF(S11,S14,"md")/7)&" Week(s) "
    Number of days

    =DATEDIF(S11,S14,"md")-INT(DATEDIF(S11,S14,"md")/7)*7&" Day(s) "
    Regards

  3. #3
    Valued Forum Contributor
    Join Date
    07-16-2007
    Location
    GA
    MS-Off Ver
    Office 365 - Version 2403
    Posts
    1,054

    Re: Calculate Years, Months Weeks

    Hi Canapone,

    Thanks for the suggested formulas.


    I added in your, =INT(DATEDIF(S11,S14,"md")/7)&" Week(s) " into my formula or to the end of it & I'm getting:

    # Years(s), # months(s)

    Instead of:

    # Years(s), # Month(s), # Week(s)


    Here's the formula:

    =IF(S14="TBD","TBD",IF(S11="","0 Years(s), 0 Month(s), 0 Day(s)",IF(S14="TBD",DATEDIF(S11,TODAY(),"y")&" year(s), "&DATEDIF(S11,TODAY(),"ym")&" month(s)",IF(S14>1,DATEDIF(S11,S14,"y")&" year(s), "&DATEDIF(S11,S14,"ym")&" month(s)",INT(DATEDIF(S11,S14,"md")/7)&" Week(s) "))))

    Now, if I use, =INT(DATEDIF(S11,S14,"md")/7)&" Week(s) "

    I get:

    0 Week(s)

    I think we are close, but not quite close enough to get:

    # Years(s), # Month(s), # Week(s)

    Any other suggestions?

    Thanks again for the assistance.

  4. #4
    Forum Expert
    Join Date
    12-03-2009
    Location
    Florence, Italy
    MS-Off Ver
    Excel 2019
    Posts
    1,796

    Re: Calculate Years, Months Weeks

    Hi, zero week means - simply put: pardon my English - we have less than 7 days.

    I would add the days: 0 week and 5 days for istance.

    Or you could add a condition "if number of week is zero", display nothing or only the days or zero week and number of days.

    Just for sharing some ideas.

    Regards

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

    Re: Calculate Years, Months Weeks

    Try this version

    =IF(S11="","0 years(s), 0 month(s), 0 week(s)",DATEDIF(S11,IF(S14="SBD",TODAY(),S14),"y")&" year(s), "&DATEDIF(S11,IF(S14="SBD",TODAY(),S14),"ym")&" month(s) "&INT(DATEDIF(S11,IF(S14="SBD",TODAY(),S14),"md")/7)&" week(s) ")
    Audere est facere

+ 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