Skip to main content
Pricoky
Known Participant
June 7, 2019
Question

How to extract date from ID-CNP number?

Hello again community. Long time no see!

I'll try to be short. I have this PDF file with form fields and along those a certain field will be filled with a person ID number with 13 digits, we call it CNP (personal numeric code). This code contains, among other info, a birth date. For example: my ID/CNP number is 1800820171721. Now the first digit, "1", means that I'm a male then the next six digits represent the birth date like so "80" is the birth year, "08" is the month and "20" is the day.

The question: What would be the correct formula for a form field to automatically extract and fill with the birth date contained in the ID/CNP field? Not necessarily in the same date format!

Thank you in advance!

Ce sujet a été fermé aux réponses.

1 commentaire

try67
Community Expert
Community Expert
June 7, 2019

You can use this code as the custom calculation script of your DOB field:

var CNP = this.getField("CNP").valueAsString;

if (CNP.length!=13) event.value = "";

else {

    var dobString = CNP.substring(1,7);

    var dobObj = util.scand("yymmdd", dobString);

    event.value = util.printd("mm/dd/yyyy", dobObj);

}

Adjust the date format in the line #6 to the one you want to use, of course.

try67
Community Expert
Community Expert
June 7, 2019

PS. Someone should tell the authorities in your country about the Y2K bug... How do they know if "18" means "2018" or "1918"?

Pricoky
PricokyAuteur
Known Participant
June 7, 2019

Then you probably should add this condition to your code, or you will get the wrong DOB...


Hmm.. now that you referred to this you've got me thinking. Although the file will be used for employees in a company and only the 18+ ones are eligible we're already in 2019 so... now I ask again: How should this condition look like?