473,545 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

547 Contributor
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.An y 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","Mal e").)

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, 155 views)
Dec 18 '16 #1
3 5380
Dormilich
8,658 Recognized Expert Moderator Expert
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 Contributor
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 Recognized Expert Moderator Expert
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
1339
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
6979
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
2994
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 of the current Windows user. I guess the name can be retrieved from the environment -- After I click the Start button of Windows, my name is on...
2
4875
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 anybody please help me //i have a parse error that i cant figure out int values = { 90, 80, 70, 60, 50, 40, 30, 20, 19, 18, 17, 16, 15, 14, 13, 12,...
1
24882
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 passed a date picked from a datepicker. public static int GetWeekNumber(DateTime dtDate) {
6
4697
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 like example above.. thanks...
9
3872
by: korea saeed | last post by:
how can i convert number string to number?(without using parsint)
0
7664
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7921
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5982
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5343
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4958
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3465
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1900
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
720
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.