+ Reply to Thread
Results 1 to 5 of 5

How to calculate just the year for a date format

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-18-2012
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    347

    How to calculate just the year for a date format

    I have a cell A1 with the value in the date format: 01/31/2008

    In another cell B1, I put the number as 3, which means the number of years forward.

    Now the question is: how can I get the new date which is just 3 years after the original date? Here in this example, the value is 01/31/2011.

    You can see only the number is added to the year only, without affecting the date or month.

    Can you give a general function / formula for this? (i.e., not necessarily 01/31/2008, it can be any date).

  2. #2
    Forum Expert ben_hensel's Avatar
    Join Date
    01-26-2012
    Location
    Northeast USA
    MS-Off Ver
    Office 365
    Posts
    2,043

    Re: How to calculate just the year for a date format

    To add three years?

    A1= date
    B1 = 3
    C1 = A1 + DATE(B1,1,-1)

  3. #3
    Forum Contributor
    Join Date
    06-18-2012
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    347

    Re: How to calculate just the year for a date format

    Hi Ben,

    You code nearly worked. But if I input: 07/02/10 , 3

    then the answer is: 07/01/13.

    Thanks in advance.


    Quote Originally Posted by ben_hensel View Post
    To add three years?

    A1= date
    B1 = 3
    C1 = A1 + DATE(B1,1,-1)

  4. #4
    Forum Expert ben_hensel's Avatar
    Join Date
    01-26-2012
    Location
    Northeast USA
    MS-Off Ver
    Office 365
    Posts
    2,043

    Re: How to calculate just the year for a date format

    Oh.... it's not handling leap-years the way you want....

    Brute force it is.

    A1 = date
    B1 = 3
    C1 = DATE(YEAR(A1)+B1,MONTH(A1),DAY(A1))
    This might not handle leap years exactly correct either... this is just adding "3" to whatever the year is and retaining the exact same number for month and day.

  5. #5
    Forum Contributor
    Join Date
    06-18-2012
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    347

    Re: How to calculate just the year for a date format

    Thanks, Ben. This is also very good.



    Quote Originally Posted by ben_hensel View Post
    Oh.... it's not handling leap-years the way you want....

    Brute force it is.

    A1 = date
    B1 = 3
    C1 = DATE(YEAR(A1)+B1,MONTH(A1),DAY(A1))
    This might not handle leap years exactly correct either... this is just adding "3" to whatever the year is and retaining the exact same number for month and day.

+ 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