Use year function to get the year : Year « Date Functions « VBA / Excel / Access / Word






Use year function to get the year

 

  Sub AgeCalc2()
      ' variable declaration
      Dim FullName$
      Dim DateOfBirth As Date
      Dim age%

      ' assign values to variables
      FullName$ = "John Smith"
      DateOfBirth = #1/3/1967#

     ' calculate age
     age% = Year(Now()) - Year(DateOfBirth)

     ' print results to the Immediate window
     MsgBox FullName$ & "is" & age% & " years old."
End Sub

 








Related examples in the same category

1.Year(Date)