+ Reply to Thread
Results 1 to 4 of 4

date formula

  1. #1
    Registered User
    Join Date
    03-30-2007
    Posts
    12

    date formula

    Can anyone help me create this function?

    I need to be able to input two dates and get the number of years (as an integer) between the dates.
    For example:
    1/4/2003 - 5/14/2008 would return 6 because we are currently in the sixth year.

    6/11/2003 - 5/14/2008 would return 5 because we are in the fifth year.

    I would also need to be sure that 5/14/2003 - 5/14/2008 would return 5.

    Any help is greatly appreciated!

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,598
    Sorry, but I don't agree with your expected results. Using birthdays as an example, a child born on 1/4/2003 would celebrate his 6th birthday on 1/4/2009 not 1/4/2008. So, using the DATEDIF fn to return years, you get 5 not 6 years. If you use that fn to return days and divide by 365 you get 5.36 years which can't legally be rounded up to 6.
    Ben Van Johnson

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    In China, a person is one year at birth ...

  4. #4
    Forum Contributor
    Join Date
    08-14-2006
    Location
    USA
    MS-Off Ver
    2019
    Posts
    686
    try this:
    =ROUNDUP(ROUND(YEARFRAC(start_year,end_year,1),2),0)

    since we're rounding to a two place decimal first then rounding up to the next whole number it should take care of the 5/14-5/14 issue

    you have to have the Analysis ToolPak Add-In enabled to use the YEARFRAC

+ 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