• DateDif (2000)

    Author
    Topic
    #419608

    =DateDiff(“Y”,[Dateofbirth],[DateofDeath])
    The above gives me the correct answer but in total days between, whereas in Excel “Y” gives the answer in Years and throws away the days, or with “D” instead of “Y” I get elapsed days. If I change the first formula in Access to “D” the D becomes d and the answer is the same as Y, M doeesn’t make any difference either.
    Can someone please tell me the correct formula

    Viewing 0 reply threads
    Author
    Replies
    • #948001

      Click in DateDiff (in the Visual Basic Editor) and press F1 to get online help. You’ll see that you need to use “yyyy” to get years.

      Here is a VBA function to calculate someone’s age in years, from an example by Microsoft:

      Function Age(Bdate, DateToday) As Integer
      ‘ Returns the Age in years between 2 dates
      ‘ Doesn’t handle negative date ranges i.e. Bdate > DateToday
      Age = Year(DateToday) – Year(Bdate)
      If Month(DateToday) < Month(Bdate) Or _
      (Month(DateToday) = Month(Bdate) And Day(DateToday) < Day(Bdate)) Then
      Age = Age – 1
      End If
      End Function

      • #948040

        Thank you very much, Hans. The age function is more suitable for my purposes than the DateDiff anyway.
        It is remarkable how few, of those to whom it would be useful, actually know about or use Woody’s lounge.
        Many thanks for your help

    Viewing 0 reply threads
    Reply To: DateDif (2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: