Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Dim intYearsElapsed As Integer
Dim intMonthsElapsed As Integer
Dim intDaysElapsed As Integer
Dim bdDate As Date
Dim bdYear As Date
Dim bdMonth As Date
Dim strPreciseAge As String
bdDate = Me!txtDate
intYearsElapsed = DateDiff("yyyy", bdDate, Date)
bdYear = DateSerial(Year(Date), Month(bdDate), Day(bdDate))
If Date < bdYear Then
intYearsElapsed = intYearsElapsed - 1
bdYear = DateAdd("yyyy", -1, bdYear)
End If
intMonthsElapsed = DateDiff("m", bdYear, Date)
bdMonth = DateSerial(Year(bdYear), Month(bdDate) + intMonthsElapsed, Day(bdDate))
If Date < bdMonth Then
intMonthsElapsed = intMonthsElapsed - 1
bdMonth = DateAdd("m", -1, bdMonth)
End If
intDaysElapsed = DateDiff("d", bdMonth, Date)
strPreciseAge = intYearsElapsed & " years, " & intMonthsElapsed & " months, " & intDaysElapsed & " days"
MsgBox strPreciseAge
Function AgeCount3(varDOB As Variant, varDate As Variant) As String
On Error GoTo Err_AgeCount3
'
' PURPOSE: Determines the difference between two dates.
'
' ARGUMENTS: (will accept either dates (e.g., #03/24/00#) or
' strings (e.g., "03/24/00")
' varDOB: The earlier of two dates.
' varDate: The later of two dates.
'
' RETURNS: A string as years.months.days, e.g., (17.6.21)
'
' NOTES: To test: Type '? agecount3("03/04/83", "03/23/00")
' in the debug window. The function will
' return "17.0.19".
Dim dteDOB As Date, dteDate As Date, dteHold As Date
Dim intOldyears As Integer, intOldMonths As Integer, intOldDays As Integer
Dim intNuYears As Integer, intNuMonths As Integer, intNudays As Integer
Dim intYears As Integer, intMonths As Integer, intDays As Integer
If IsDate(varDOB) And IsDate(varDate) Then
dteDOB = DateValue(varDOB)
dteDate = DateValue(varDate)
'Reverse the dates if they were input backwards
If dteDOB > dteDate Then
dteHold = dteDOB
dteDOB = dteDate
dteDate = dteHold
End If
intOldyears = Year(dteDOB)
intOldMonths = Month(dteDOB)
intOldDays = Day(dteDOB)
intNuYears = Year(dteDate)
intNuMonths = Month(dteDate)
intNudays = Day(dteDate)
If intNudays < intOldDays Then
intNudays = intNudays + 30
intNuMonths = intNuMonths - 1
End If
If intNuMonths < intOldMonths Then
intNuMonths = intNuMonths + 12
intNuYears = intNuYears - 1
End If
intYears = intNuYears - intOldyears
intMonths = intNuMonths - intOldMonths
intDays = intNudays - intOldDays
AgeCount3 = LTrim(Str(intYears)) & "." & LTrim(Str(intMonths)) & "." & LTrim(Str(Int(intDays)))
Else
MsgBox "Invalid date parameters -- please try again", vbOKOnly, "Check input dates!"
GoTo Exit_AgeCount3
End If
Exit_AgeCount3:
Exit Function
Err_AgeCount3:
Select Case Err.Number
Case 0
Resume Next
Case Else
MsgBox Err.Number & ": " & Err.Description
End Select
Resume Exit_AgeCount3
End Function
Dim intYearsElapsed As Integer
Dim intMonthsElapsed As Integer
Dim intDaysElapsed As Integer
Dim bdDate As Date
Dim bdYear As Date
Dim bdMonth As Date
Dim strPreciseAge As String
bdDate = Me!txtDate
intYearsElapsed = DateDiff("yyyy", bdDate, Date)
bdYear = DateSerial(Year(Date), Month(bdDate), Day(bdDate))
If Date < bdYear Then
intYearsElapsed = intYearsElapsed - 1
bdYear = DateAdd("yyyy", -1, bdYear)
End If
intMonthsElapsed = DateDiff("m", bdYear, Date)
bdMonth = DateSerial(Year(bdYear), Month(bdDate) + intMonthsElapsed, Day(bdDate))
If Month(Date) <> Month(bdMonth) Then
bdMonth = DateSerial(Year(bdYear), Month(bdDate) + intMonthsElapsed - 1, Day(bdDate))
intMonthsElapsed = intMonthsElapsed - 1
ElseIf Date < bdMonth Then
intMonthsElapsed = intMonthsElapsed - 1
bdMonth = DateAdd("m", -1, bdMonth)
End If
intDaysElapsed = DateDiff("d", bdMonth, Date)
strPreciseAge = intYearsElapsed & " years, " & intMonthsElapsed & " months, " & intDaysElapsed & " days"
MsgBox strPreciseAge