Skip to main content
Participant
March 16, 2023
Resuelto

Comparing dates in JavaScript

  • March 16, 2023
  • 3 respuestas
  • 957 visualizaciones

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!

Este tema ha sido cerrado para respuestas.
Mejor respuesta de try67

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 respuestas

try67
Community Expert
try67Community ExpertRespuesta
Community Expert
March 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

Participant
July 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.

Bernd Alheit
Community Expert
Community Expert
July 19, 2023

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