473,326 Members | 2,090 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,326 software developers and data experts.

Needs dd/mm/yyyy birthdate format from a string in javascript

547 512MB
I need to change a South African ID number to the date of birth (DOB)dd/mm/yyyy using javascript
example of ID Number - 0203185149088.
My code gives it as 18/03/02 instead of 18/03/2002 and if ID No is 6202185155087 then i get 18/02/62 and not 18/02/1962
The years before 2000 and after needs to be added please
dd/mm/yyyy
Please assist
Expand|Select|Wrap|Line Numbers
  1.     <form>
  2.         <input type="text" name="idno" id="idno" value="" placeholder="ID Number" onkeyup="dateOfBirthsum();" />
  3.         <input type="text" name="dob" id="dob"  placeholder="birthdate"/>
  4.  
  5.     </form>
javascript
Expand|Select|Wrap|Line Numbers
  1. <script>
  2.  
  3. function dateOfBirthsum()
  4. {    var idnumInput = document.getElementById('idno').value;
  5.  
  6.     var dateDay = idnumInput.substring(4,6);
  7.     var dateMonth = idnumInput.substring(2,4);
  8.     var dateYear = idnumInput.substring(0,2);
  9.    var result = dateDay + "/" + dateMonth + "/" + dateYear;
  10.     document.getElementById('dob').value = result;
  11.     }
  12.     </script>

I got this code somewhere but cannot add it
Expand|Select|Wrap|Line Numbers
  1. var year          = id_number.substr ( 0  , 2 );
  2.                     var nowYearNotCentury = currentTime.getFullYear() + '';
  3.                     nowYearNotCentury = nowYearNotCentury.substr(2,2);
  4.                     if (year <= nowYearNotCentury){
  5.                         date = '20' + year+ "-" + id_number.substr(2, 2) + "-" + id_number.substr(4, 2);
  6.                     } else {
  7.                         date = '19' + year+ "-" + id_number.substr(2, 2) + "-" + id_number.substr(4, 2);
  8.                     }//end if
Mar 21 '17 #1
4 1351
neelsfer
547 512MB
After 3 hours of struggling, i got it working. Anybody else needing a very basic solution, here it is
Expand|Select|Wrap|Line Numbers
  1.  <body>
  2.     <form>
  3.         <input type="text" name="idno" id="idno" value="" placeholder="ID Number" onkeyup="dateOfBirthsum();" />
  4.  
  5.         <input type="text" name="dob2" id="dob2"  placeholder="birthdate2"/>
  6.     </form>
  7. <script>
  8.  
  9. function dateOfBirthsum()
  10. {    var idnumInput = document.getElementById('idno').value;
  11.  
  12.     var dateDay = idnumInput.substring(4,6);
  13.     var dateMonth = idnumInput.substring(2,4);
  14.     var dateYear = idnumInput.substring(0,2);
  15.  
  16.     var dateYear1 = '19' + dateYear;
  17.     var dateYear2 = '20' + dateYear;
  18.     var Year1 = dateYear;
  19.     var Year2 = dateYear;
  20.     var years = new Date();
  21.     var dateYear3 = years.getFullYear();
  22.     var dateYear3a = idnumInput.substring(0,2);
  23.  
  24.   if (dateYear1 < dateYear3a){
  25.             result3    = dateDay + "/" + dateMonth + "/" + '19' + dateYear;
  26.                     } else {
  27.                         result3    = dateDay + "/" + dateMonth + "/" + '20' + dateYear;
  28.                     }
  29.  
  30.     document.getElementById('dob2').value = result3;
  31.  
  32.     }
  33.     </script>
Mar 21 '17 #2
Dormilich
8,658 Expert Mod 8TB
out of curiousity, how do you determine the DoB for people older than 100 years?
Mar 22 '17 #3
neelsfer
547 512MB
Thx for comment. It is for a cycling races online registration site. I don't expect to many 101 year old cyclist's to enter.
Mar 22 '17 #4
Dormilich
8,658 Expert Mod 8TB
OK. please keep us updated, if they do.
Mar 22 '17 #5

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

Similar topics

3
by: Sansanee | last post by:
Hi, I am wondering if there is any format string for phone number. Just like those dd:mm:yyyy or C for currency. Can anyone enlighten me? Thank you in advance, Sunny
6
by: Servé Lau | last post by:
suppose I want to use sscanf get the functionname from a function prototype. Is the following format string correct then? char funcname; char *p = "func(void)"; sscanf(p, "%s", funcname);...
3
by: Özgür Aytekin | last post by:
How can I display the hundredth of a second or which is the correct format string? I use now {0:yyyy-MM-dd HH:mm:ss} and this display the following information: 2004-08-04 21:49:21... But I...
7
by: Eddy Soeparmin | last post by:
Hi, I need to display a DateTime field in 'mm/dd/yyyy' in a DataGrid.. On myGrid1 - Properties - Columns - myColumn1 - Text format string: I tried to put 'mm/dd/yyyy' in there and it displays...
3
by: stathisgotsis | last post by:
Hello everyone, Trusting K&R2 i thought until recently that spaces are ignored in scanf's format string. Reading arguments to the contrary confused me a little. So i now ask: Is...
2
by: gregpinero | last post by:
I might just be being dumb tonight, but why doesn't this work: Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: not enough arguments for format string (I'm in Python...
2
by: stainless | last post by:
I know this is probably simple but I cannot find a method of converting a date string into a format that matches the DatePicker format in C# eg string "20080131" converted to "31 January 2008" ...
3
by: gregcm | last post by:
I've got a custom control that is trying to allow the user to enter a DateTime in a definable format and I was wondering if there was an easy way to alter the look of said control based on the...
7
by: moondaddy | last post by:
I need to format a string to it always has 2 digits in it. I'm getting the month like this: DateTime.Now.Month.ToString() Right now since it's August, this returns a string of "8", however, I...
7
by: Andrus | last post by:
How to create format string for decimal data type which shows blank for zero and default format otherwize ? I tried format string "f;f;#" but this shows f for nonzero numbers. Andrus. ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.