+ Reply to Thread
Results 1 to 4 of 4

DateDiff

  1. #1
    Forum Contributor vandanavai's Avatar
    Join Date
    09-04-2006
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    256

    DateDiff

    I want to use DateDiff function in VBA(UDF) to do following

    Date of Birth : A1
    Year end Date : B1
    check if person has completed 65 years of age before B1

    Please help.

  2. #2
    Forum Contributor
    Join Date
    07-05-2006
    Location
    Canada
    MS-Off Ver
    2003, 2007
    Posts
    581
    I'm not sure you can. DateDiff("yyyy", ....) just returns the difference in the year values (ie. December 31, 1941 and January 1, 2006 are 65 years apart).

    You'd be better to use the equivalent of the Excel formula:

    =Date(Year(A1)+65,Month(A1),Day(A1)) and check to see if this is greater than or equal to the date in B1. It even works for leap years. :-)

    Scott

  3. #3
    Registered User
    Join Date
    11-19-2006
    Posts
    15

    DateDif

    Try this, you don't need VBA just use the function (formula)

    =IF(DATEDIF(A1,B1, "Y")=65,TRUE,FALSE)

    What this does is if the person reached the age of 65 by B1 the formula returns True if not it returns False.

    Hope this helps.

    Garf

  4. #4
    Registered User
    Join Date
    11-19-2006
    Posts
    15

    DateDif Again

    Sorry I forgot you wanted to see if the person reached the age of 65 before B1.
    Well you have to ask a question, what determines before B1 what point in time do we use. I used today’s date Now(), as follows:

    =IF(DATEDIF(A1,NOW(), "Y")=65,TRUE,DATEDIF(A1,B1,"Y"))

    This formula finds the age of the person from A1 to now, if the person has reached 65 the formula returns True, if not it finds the age between A1 & B1 and returns the age between the two dates. This way if the person reaches 65 by today you know it, if not you know how old the person is based on the two dated A1-B1.

    Hope this helps.

+ 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