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

Comparing dates in JavaScript

New Here ,
Mar 16, 2023 Mar 16, 2023

Hey there, I have a given date which is a form field "Case.DATE(Date dd.MM.yyyy)", and need to check, if it's before or after the 14.09.2022.

Based on that, another form field should just be filled in with an "x".
Is that possible with a util function?
Also, is there a way to automatically subtract 3 days from that given date?
Thousand thanks in Advance!

TOPICS
Acrobat SDK and JavaScript
683
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

correct answers 1 Correct answer

Community Expert , Mar 16, 2023 Mar 16, 2023

Yes, both of these things are possible. You should convert the value of the form field to a Date object using the util.scand method (make sure it's not empty first, though!) and create another Date object for the threshold date, and then compare the two by using their getTime methods.

 

To subtract 3 days from a Date object you can use its setDate and getDate methods, like this:

var d = new Date(); // d is the current date

d.setDate(d.getDate()-3); // d is now the current date minus 3 days

Translate
Community Expert ,
Mar 16, 2023 Mar 16, 2023

Yes, both of these things are possible. You should convert the value of the form field to a Date object using the util.scand method (make sure it's not empty first, though!) and create another Date object for the threshold date, and then compare the two by using their getTime methods.

 

To subtract 3 days from a Date object you can use its setDate and getDate methods, like this:

var d = new Date(); // d is the current date

d.setDate(d.getDate()-3); // d is now the current date minus 3 days

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
New Here ,
Jul 19, 2023 Jul 19, 2023

Is this also possible, if the original field, on which the calculation is based, is empty?

I only could get it to work while manually filling in the field.

The Formfields on our PDFs are always emtpy and being filled while processed by the system.

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 ,
Jul 19, 2023 Jul 19, 2023
LATEST

When the field is empty don't perform the calculation.

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