Public Function AgeFromGovID(ByVal pID As String) As Integer
Dim dt As Date
pID = pID & ""
If Len(p) = 0 Then
Exit Function
End If
dt = DateSerial(Left$(pID, 2), Mid$(pID, 3, 2), Mid$(pID, 5, 2))
AgeFromGovID = AgeYears(dt)
End Function
Public Function AgeYears(ByVal datBirthDate As Date) As Integer
' Comments: Returns the age in years
' Params : datBirthDate Date to check
' Returns : Number of years
' Source : Total Visual SourceBook
On Error GoTo Proc_Err
Dim intYears As Integer
intYears = Year(Now) - Year(datBirthDate)
If DateSerial(Year(Now), Month(datBirthDate), Day(datBirthDate)) > Now Then
' Subtract a year if birthday hasn't arrived this year
intYears = intYears - 1
End If
AgeYears = intYears
Proc_Exit:
Exit Function
Proc_Err:
MsgBox "Error: " & Err.Number & ". " & Err.description, , "modDateTime.AgeYears"
Resume Proc_Exit
End Function
May I ask why Right([govID], 2)?more or less:
=DateDiff("yyyy", DateSerial(Left([govID], 2), Mid([govID], 3, 2), Right([govID], 2)), Date())
yes it working.. tq for the guidemore or less:
=DateDiff("yyyy", DateSerial(Left([govID], 2), Mid([govID], 3, 2), Mid([govID], 5, 2)), Date())
got issue when born year = 2000you should also try the Function, it is more accurate.
say, the month is not May but Nov.
=DateDiff("yyyy", DateSerial(Left([govID], 2), Mid([govID], 3, 2), Mid([govID], 5, 2)), Date())
will return 24 also. but this is not True since it is only June and the correct Age is 23.
Private Sub Report_Load()
umor1 = DateDiff("yyyy", DateSerial(Left([TGuruIPS.NoKP], 2), Mid([TGuruIPS.NoKP], 3, 2), Mid([TGuruIPS.NoKP], 5, 2)), Date)
End Sub
sory2 wrong calculation ?it is evaluating 03 as 2003 and the calculation is Correct, 19.
if the real Age is 29, the first 2 digit should be "93" (1993)?
what do you think?
look at your sample on post #1.
if this is not the case, then you cannot say that
the first 2 digit is the Year.
Public Function AgeFromGovID(ByVal pID As String) As Integer
Dim dt As Date
pID = pID & ""
If Len(p) = 0 Then
Exit Function
End If
dt = DateSerial(Left$(pID, 2), Mid$(pID, 3, 2), Mid$(pID, 5, 2))
AgeFromGovID = AgeYears(dt)
End Function
Public Function AgeYears(ByVal datBirthDate As Date) As Integer
' Comments: Returns the age in years
' Params : datBirthDate Date to check
' Returns : Number of years
' Source : Total Visual SourceBook
On Error GoTo Proc_Err
Dim intYears As Integer
intYears = Year(Now) - Year(datBirthDate)
If DateSerial(Year(Now), Month(datBirthDate), Day(datBirthDate)) > Now Then
' Subtract a year if birthday hasn't arrived this year
intYears = intYears - 1
End If
AgeYears = intYears
Proc_Exit:
Exit Function
Proc_Err:
MsgBox "Error: " & Err.Number & ". " & Err.description, , "modDateTime.AgeYears"
Resume Proc_Exit
End Function
thanks for the helpput it in a Module.
see this demo.
Does that mean you govt id is rubbish?HI,
got issue when born year = 2000
C#:Private Sub Report_Load() umor1 = DateDiff("yyyy", DateSerial(Left([TGuruIPS.NoKP], 2), Mid([TGuruIPS.NoKP], 3, 2), Mid([TGuruIPS.NoKP], 5, 2)), Date) End Sub
031118-04-0350the code show (19) real age is 29
03 = year born 2003 (my gov id 03)
11 = month
18 = day