Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Script to calculate age from first 6 digits of a 10 digit number (DDMMYYXXXX)

Avatar

Level 3

I have a  "numeric field" which will contain a 10 digit number; the fist 4 digits being the date of birth (DDMMYY). 

I would really like to have another field where the DOB is automatically calculated from this. I'd appreciated any help - I have pretty much zero knowledge of scripting.

1 Accepted Solution

Avatar

Correct answer by
Employee

ok, I think I can see the problem. CHI is a numeric field and not a text field. Therefore the CHId is not a string but a digital number - that means that "0101191234" is actually a numeric value of 101191234. That cannot be dismantled with substring.

Change the CHI field to textfield and then try again.I tested your fields with the correct type and then it works:

kprokopi_0-1598614241180.pngkprokopi_1-1598614314930.png

To force format and length of CHI limit max characters

kprokopi_0-1598619725694.png

Display and validation patterns text{9999999999} and error on validation

kprokopi_1-1598619785968.pngkprokopi_2-1598619812681.png

 

 

 

View solution in original post

0 Replies

Avatar

Level 3

Thanks kprokopi - the script works fine on the form you sent. But when I copy and past those 3 fields to my own form, it does't work and I get a huge number!

 

Yours: https://imgur.com/gallery/9ucexUm

 

Mine: https://imgur.com/gallery/NLojPoo

 

I also looks like the date format is different in the 2nd box - I don't why this could be, as I just copied across from your form to mine!

 

Edit: this should have been a reply to the other thread about the 2 date fields, sorry! I've commented there also. 

Avatar

Level 4
The screenshot shows that the 2 date fields show different formatting depending n locale and formatting settings - you need to have them the same