Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Date Calculation without error without / between dates

Participant ,
May 27, 2020 May 27, 2020

Hi,

 

I have manged to find a javascript that does the date calculation which worked with the date typed as 29/12/1961, now the customer want the date just typed as 29121961 in a text filed set to comb 8 characters now the calculation doesn't work, I've tried removing the / from this line of the javascript
dob = util.scand("dd/mm/yyyy", dobValue); but still no luck.

I've attached 2 test PDFs number 1 works ok number 2 doesn't, and also the working javascript below.

Unfortunately I do not have the skill to work this out and hopefully someone else will if at all possible

Thanks in advance  

Paul

Javascript used below

 

dobValue = getField("DOB").value; if (dobValue!="") { dob = util.scand("dd/mm/yyyy", dobValue); var nTimeDiff = (new Date()).getTime() - dob.getTime(); var nYears = nTimeDiff/(365*24*60*60*1000); event.value = nYears; }

TOPICS
PDF forms
2.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
2 ACCEPTED SOLUTIONS
Community Expert ,
May 27, 2020 May 27, 2020

Use:

var dobValue = getField("DOB").valueAsString;

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 29, 2020 May 29, 2020

Change the first line to:

var dobValue = getField("DOB").valueAsString;

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 27, 2020 May 27, 2020

Use:

util.scand("ddmmyyyy", dobValue)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 27, 2020 May 27, 2020

Hi,

 

Thank for the reply, I've tried this and it just errors

 

thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 27, 2020 May 27, 2020

What does the error message say?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 27, 2020 May 27, 2020

I just get the javascript debugger console with all these errors

 

TypeError: this.getField(...) is null 1:Field:Format TypeError: this.getField(...) is null 1:AcroForm:Date of Birth:Format TypeError: this.getField(...) is null 24:Document-Level:Age TypeError: this.getField(...) is null 24:Document-Level:Age TypeError: this.getField(...) is null 24:Document-Level:Age TypeError: this.getField(...) is null 1:AcroForm:Date:Format TypeError: dob is null 9:Field:Calculate TypeError: dob is null 9:AcroForm:Age:Calculate TypeError: dob is null 9:Field:Calculate TypeError: dob is null 9:AcroForm:Age:Calculate TypeError: dob is null 9:Field:Calculate TypeError: dob is null 9:Field:Calculate TypeError: dob is null 9:Field:Calculate

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 27, 2020 May 27, 2020

Post your full code, please, or the file itself.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 29, 2020 May 29, 2020

Hi sorry for the delay in replying, here is the file that is erroring I also tried Bernd Alheit suggestion but tat didn't seem to work either

 

Sorry the file is on a we transfer link below aas couldn't seem to attached to this list

 

https://we.tl/t-HpPdxNAvPH

 

Thanks all for your help

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 29, 2020 May 29, 2020

Change the first line to:

var dobValue = getField("DOB").valueAsString;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 29, 2020 May 29, 2020
LATEST

Thats brillant, working now.

Thank you all and have a great weekend

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 27, 2020 May 27, 2020

Use:

var dobValue = getField("DOB").valueAsString;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines