Skip to main content
Inspiring
January 4, 2023
Question

Convert a German Date to a date taht can be parsed in JS

  • January 4, 2023
  • 1 reply
  • 1143 views

In our German forms dates are always written "dd.mm.yyyy" e.g. today = 04.01.2023

If I want to use the parse() function to compare dates I have to convert them to the general format yyyy-mm-dd

Of course you could dissect the Date-String and put it together again - but is there really no easy way?

This topic has been closed for replies.

1 reply

Nesa Nurani
Community Expert
Community Expert
January 4, 2023

Are you trying to compare two dates?

You can try like this:

var date1 = util.scand("dd.mm.yyyy", this.getField("Date1").valueAsString);
var date2 = util.scand("dd.mm.yyyy", this.getField("Date2").valueAsString);

GGNAuthor
Inspiring
January 16, 2023

Thank you very much @Nesa Nurani !

Eventually I want to extract just the year from of a date, so I can calculate the age of a building [year of the start-date (Beginn) - year of construction (Baujahr)] The Baujahr is delivered as a 4-digit number = the year, not as a date.

 

But I even have trouble to use your commands. When I tried your command in the console it seemingly did work fine:

I've changed the date and tried the same thing with variable, seems okay:

I've changed the date again and - but the console kept on working with the old date:

No matter what I tried, the date stuck to 10/12/2023 ...

I closed the form (and later the program too) and now the commands don't even recognize the date any more ...??

I was interrupted for a while and started all over again. Now without the Variable it worked fine, even with dates changed:

But trying to use the variable again -> undefined ... 

 

That's something that gives me a lot of trouble. It seems that Acrobat has some kind of cache that isn't handled properly ... the same form on the same computer with same datas sometimes works and sometimes fails, and no idea why. Okay the forms I'm working on are not in best shape, and I also have to admit, that I'm not an IT-expert, but I also work with SQL and SPL (a rather ancient derivative of C) and I always could rely, that same data, same script at least produces the same error ...

 

 

 

 

 

Bernd Alheit
Community Expert
Community Expert
January 16, 2023

How does you execute the script? Try a other name for the variable.