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

zum aktuellen Datum ein Jahr hinzufügen

New Here ,
Aug 11, 2019 Aug 11, 2019

Copy link to clipboard

Copied

Hallo liebes Forum,

ich habe ein Formular erstellt, in dem ich ein Datumsfeld mit dem aktuellen Tagesdatum habe (wird beim Anklicken eingetragen - Format dd/mm/yy). Das Feld heißt "Prüfdatum". Nun gibt es noch ein weiters Feld namens "nächste Prüfung" (Format mm/yy).

Nun möchte ich, dass im Feld nächste Prüfung der Wert des aktuellen Prüfdatums + 1 Jahr steht.

Beispiel: Feld Prüfdatum = 11.08.19

               Feld nächste Prüfung = 08/20

Leider bekomme ich das nicht hin.

Kann mir jemand das komplette JavaScript dafür nennen?

Mfg Michael Kettner

TOPICS
Acrobat SDK and JavaScript

Views

383

Translate

Translate

Report

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 , Aug 11, 2019 Aug 11, 2019

You can use this code as the custom calculation script of the second field:

event.value = "";

var v = this.getField("Prüfdatum").valueAsString;

if (v!="") {

    var d = util.scand("dd/mm/yy", v);

    if (d!=null) {

        d.setFullYear(d.getFullYear()+1);

        event.value = util.printd("mm/yy", d);

    }

}

I don't know how critical this is, but be aware that if the date is 29/02 on a leap year (like 29/02/2020), the result of this code will be "03", not "02" ("03/21" in the example above)...

Votes

Translate

Translate
Community Expert ,
Aug 11, 2019 Aug 11, 2019

Copy link to clipboard

Copied

You can use this code as the custom calculation script of the second field:

event.value = "";

var v = this.getField("Prüfdatum").valueAsString;

if (v!="") {

    var d = util.scand("dd/mm/yy", v);

    if (d!=null) {

        d.setFullYear(d.getFullYear()+1);

        event.value = util.printd("mm/yy", d);

    }

}

I don't know how critical this is, but be aware that if the date is 29/02 on a leap year (like 29/02/2020), the result of this code will be "03", not "02" ("03/21" in the example above)...

Votes

Translate

Translate

Report

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 ,
Aug 11, 2019 Aug 11, 2019

Copy link to clipboard

Copied

Hallo try67,

vielen Dank, es funktioniert. Mit dem Problem des 29.02. im Schaltjahr kann ich vorerst leben.

Viele Grüsse

Michael Kettner

Votes

Translate

Translate

Report

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 ,
Aug 11, 2019 Aug 11, 2019

Copy link to clipboard

Copied

Hallo try67,

ich muss eine kleine Einschränkung machen. Auf meinem Windows-PC funktioniert es wunderbar. Wenn ich das Formular jedoch per Email auf ein Android-Gerät sende, so funktioniert die Berechnung nicht mehr. Ich kann das Formular auf dem Smartphone ausfüllen und per Mail zurücksenden. Wenn ich es dann wieder auf meinen PC zurücksende funktioniert es auch nicht. Alle Daten sind bis auf das berechnete Feld richtig vorhanden.

Schade, dennoch vielen Dank!

Mfg Michael Kettner

Votes

Translate

Translate

Report

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 ,
Aug 12, 2019 Aug 12, 2019

Copy link to clipboard

Copied

LATEST

Sorry, I can't help you with that. Almost no scripts work on mobile devices, unfortunately.

It might be possible to achieve it, but it requires a lot of trial and error and a lot of testing.

Votes

Translate

Translate

Report

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