473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Convert ID Number to Birthdate, gender and age as of 31/12 of current yr

547 512MB
I am a new, "trying to be" PHP Html and MySqli programmer coming from Ms Access and VB background. Can somebody please assist, as I am stuck and sweating with these calculations.Any suggestions on how to populate the relevant input text boxes in realtime when adding an IDNo to the screen in input textbox called IDNO? Currently it only populate the mysqli database on pressing the submit button.

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
  1. function getBirthdateFromIdentity($identity) {
  2.     // substring identity to get bday
  3.     $date = substr($identity, 0, 6);
  4.  
  5.     // use built-in DateTime object to work with dates
  6.     $date = \DateTime::createFromFormat('ymd', $date);
  7.     $now  = new \DateTime();
  8.  
  9.     // compare birth date with current date: 
  10.     // if it's bigger bd was in previous century
  11.     if ($date > $now) {
  12.         $date->modify('-100 years');
  13.     }
  14.  
  15.     return $date;
The 7th digit indicates male or female ie 0-4 = female and 5-9 = male , So
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
  1. function getGenderFromIdentity($identity) {
  2.     // substring gender data and convert it to int
  3.     $gender = (int) substr($identity, 6, 1);
  4.     return ($gender >= 0 && $gender <= 4) ? 'Female' : 'Male';
  5. }
  6.  */
Lastly i also need to calculate the AGE of this person from the birthdate as of 31 December of current year (NOT TODAY as this code shows)
In PHP as of today i use
Expand|Select|Wrap|Line Numbers
  1. function getAgeFromBirthday(\DateTime $birthdate) {
  2.     $date = new DateTime();
  3.     $interval = $date->diff($birthdate);
  4.     return $interval->y;
  5. }

(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.
Attached Files
File Type: zip files.zip (2.8 KB, 154 views)
Dec 18 '16 #1

✓ answered by Dormilich

Any suggestions on how to populate the relevant input text boxes in realtime
for realtime actions (i.e. user interactions) you need JavaScript. PHP always requires a round trip to the server.

3 5317
Dormilich
8,658 Expert Mod 8TB
Any suggestions on how to populate the relevant input text boxes in realtime
for realtime actions (i.e. user interactions) you need JavaScript. PHP always requires a round trip to the server.
Dec 19 '16 #2
neelsfer
547 512MB
I suppose all the code needs to be rewritten from PHP to Javascript? One cannot only adjust it?
Dec 19 '16 #3
Dormilich
8,658 Expert Mod 8TB
One cannot only adjust it?
No matter what you adjust in PHP, you will never get immediate user interaction.

Mind, PHP only runs on the server. if you want direct user interaction you must use some JS. Although you can use JS to let PHP do stuff (=> AJAX), the type of calculation can be done in JS as well as it is quite simple.
Jan 2 '17 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: vhormaza | last post by:
Hello. Have some body a function to convert a number in the alphabetical expression?, for example-. 1500 = Mil Quinientos (in spanish)
2
by: mktilu | last post by:
hi can any one tell do we have any function to convert number to text.For example 25 to be converted to twenty five in SQL
9
by: Alex | last post by:
Get the Name and Phone Number of the Current Windows User in a .NET Application I am writing a simple .NET (C#) application. It needs to "automatic" get the Name (last, first) and phone number...
2
by: nineballssj9 | last post by:
#include <stdio.h> #include <string.h> #include <math.h> //i'm trying to convert number into word like for an example if i type //99.99 then it will print ninety nine point ninety nine //can...
1
LoanB
by: LoanB | last post by:
Hey gang Need some help please. Below I have code which returns the week number of the year. I need some code which simalarly return the week number of the current month. dtDate below gets...
6
by: maminx | last post by:
hello... i have this situation, i want to convert the number format like example "350", become string format "three hundred and fifty".. Is it anyone who has the library to convert the number...
9
by: korea saeed | last post by:
how can i convert number string to number?(without using parsint)
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.