Skip to main content
Participant
Mar 16, 2023 10:50 AM UTC
Answered

Comparing dates in JavaScript

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!

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Mar 16, 2023 11:02 AM UTC

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

3 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Mar 16, 2023 11:02 AM UTC

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
Participant
Jul 19, 2023 12:58 PM UTC

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
Bernd Alheit
Community Expert
Community Expert
Jul 19, 2023 1:07 PM UTC

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

Translate