Example Identity number = 63021854485519
The Birthdate from this = dd/mm/yyyy = 18/02/1963
In PHP this works, but it does not populate Birthdate input text box in realtime as IDNo is added.
Expand|Select|Wrap|Line Numbers
- function getBirthdateFromIdentity($identity) {
- // substring identity to get bday
- $date = substr($identity, 0, 6);
- // use built-in DateTime object to work with dates
- $date = \DateTime::createFromFormat('ymd', $date);
- $now = new \DateTime();
- // compare birth date with current date:
- // if it's bigger bd was in previous century
- if ($date > $now) {
- $date->modify('-100 years');
- }
- return $date;
this person's Id No indicates its a Male as 7th digit is 5 (between 5-9)
In PHP this works but does not populate gender input textbox in realtime as IDNo is added
Expand|Select|Wrap|Line Numbers
- function getGenderFromIdentity($identity) {
- // substring gender data and convert it to int
- $gender = (int) substr($identity, 6, 1);
- return ($gender >= 0 && $gender <= 4) ? 'Female' : 'Male';
- }
- */
In PHP as of today i use
Expand|Select|Wrap|Line Numbers
- function getAgeFromBirthday(\DateTime $birthdate) {
- $date = new DateTime();
- $interval = $date->diff($birthdate);
- return $interval->y;
- }
(In VB to calculate birthdate from ID No I use ---> DOB=Mid([idno],5,2) & "/" & Mid([idno],3,2) & "/" & Mid([idno],1,2) Require as dd/mm/yyyy.
(PHP
In VB to calculate Gender I use --> Gender=IIf(Mid([idno],7,1) Between 0 And 4,"Female","Male").)
To summarize how can i populate the birthdate, gender and age on screen to the relevant input textboxes, after entering the IDNO onscreen. Pls advise as this causing nightmares in my life.