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

How to extract date from ID-CNP number?

  • June 7, 2019
  • 1 reply
  • 2953 views

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!

This topic has been closed for replies.

1 reply

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
PricokyAuthor
Known Participant
June 7, 2019

Thank you Sir you are awesome, the code works flawlessly !!!

PS: Well it seems they fixed this issue like this: The ID of a male born in 1918 will begin with "1" and for female with "2" and for the ones born after the year of 2000 the first digit will be "5 for male and "6" for female.