Solved how to get AGE from my idenfication no format

Akai90

Member
Local time
Today, 13:43
Joined
Feb 8, 2022
Messages
67
hi.

is there any where to get AGE value from idenfication no
my gov id format like this.

980530-04-1233

98 = yy
05 = mm
30 = dd

i like to get age no to show on form and report.

thanks
 
more or less:

=DateDiff("yyyy", DateSerial(Left([govID], 2), Mid([govID], 3, 2), Mid([govID], 5, 2)), Date())
 
Last edited:
you can also create a function to get the date from your id:
Code:
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
 
more or less:

=DateDiff("yyyy", DateSerial(Left([govID], 2), Mid([govID], 3, 2), Right([govID], 2)), Date())
May I ask why Right([govID], 2)?
Shouldn't it be Mid([govID],5,2)?
 
Last edited:
I edited it since.
At first i test it only on the first part of the text (right of -)
 
you 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.
 
HI,

you 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.
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-0350 the code show (19) real age is 29

03 = year born 2003 (my gov id 03)
11 = month
18 = day
 
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.
 
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.
sory2 wrong calculation ?

can i ask question about
C#:
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

where to put it and any code to modified ?
 
put it in a Module.
see this demo.
 

Attachments

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-0350 the code show (19) real age is 29

03 = year born 2003 (my gov id 03)
11 = month
18 = day
Does that mean you govt id is rubbish? :)
 

Users who are viewing this thread

Back
Top Bottom