McMillan's Visual Basic Code - Code Snippets - CalculateAge Function
Code Snippets
Home



Calculate a person's age with the CalculateAge Function

Option Explicit

Public Function CalculateAge(BirthDate As String) As Long

   Dim y As Long

   y = DateDiff("yyyy", BirthDate, Date)
   If DateDiff("d", Day(BirthDate) & "/" & Month(BirthDate), Date) < 0 Then
      CalculateAge = y - 1
   Else
      CalculateAge = y
   End If

End Function

© Copyright Notice

Unless otherwise stated, the code on this site is Copyright to Andrew McMillan. You may use this code in your projects (both commercial and non-commercial) but you are not permitted to republish this code in any form without the Author's prior consent.

The code on this site is supplied "as is" and no claims are made as to its soundness. The Author claims no responsibility for or liability from use of said source code.


Home