Function Dates Times Class ★ Top 20 Most Useful

AgeDifference

Return the difference in years between the two dates. vCountTime determines whether Time is considered within the calculation.

Signature (Visual Basic / VBA)

Public Function AgeDifference( _
      ByVal vFromDate As Variant _
    , ByVal vToDate As Variant _
    , Optional ByVal vCountTime As Variant _
    ) As Variant

Code Example

    AgeDifference(#1/1/70#, #1/1/96#) = 26
    AgeDifference(#1/1/70#, #5/1/96#) = 26
    AgeDifference(#9/1/70#, #5/1/96#) = 25
    AgeDifference(#1/1/70 9:00#, #1/1/96 5:00#) = 26
    AgeDifference(#1/1/70 9:00#, #1/1/96 5:00#, True) = 25

Parameters

Parameter Description
vFromDate The earlier of the two dates for which the difference in years will be calculated. Function returns Null if vFromDate is Null or cannot be fixed up to a Date.
vToDate The later of the two dates for which the difference in years will be calculated. Function returns Null if vFromDate is Null or cannot be fixed up to a Date.
vCountTime True if the calculation should take into account the time components of vFromDate and vToDate, or False if it should examine only their date components. vCountTime defaults to False (only the date components will be used) if it is missing or Null or cannot be fixed up to a number.