Solved how to get AGE from my idenfication no format (1 Viewer)

Akai90

Member
Local time
Today, 21:00
Joined
Feb 8, 2022
Messages
65
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
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:00
Joined
May 7, 2009
Messages
19,249
more or less:

=DateDiff("yyyy", DateSerial(Left([govID], 2), Mid([govID], 3, 2), Mid([govID], 5, 2)), Date())
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:00
Joined
May 7, 2009
Messages
19,249
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
 

KitaYama

Well-known member
Local time
Today, 22:00
Joined
Jan 6, 2022
Messages
1,604
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:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:00
Joined
May 7, 2009
Messages
19,249
I edited it since.
At first i test it only on the first part of the text (right of -)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:00
Joined
May 7, 2009
Messages
19,249
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.
 

Akai90

Member
Local time
Today, 21:00
Joined
Feb 8, 2022
Messages
65
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
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:00
Joined
May 7, 2009
Messages
19,249
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.
 

Akai90

Member
Local time
Today, 21:00
Joined
Feb 8, 2022
Messages
65
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 ?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:00
Joined
May 7, 2009
Messages
19,249
put it in a Module.
see this demo.
 

Attachments

  • GovID.accdb
    560 KB · Views: 103

Gasman

Enthusiastic Amateur
Local time
Today, 14:00
Joined
Sep 21, 2011
Messages
14,559
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

Top Bottom