Skip to main content
Participant
August 11, 2019
Answered

zum aktuellen Datum ein Jahr hinzufügen

  • August 11, 2019
  • 2 replies
  • 687 views

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

This topic has been closed for replies.
Correct answer try67

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)...

2 replies

Mick2712Author
Participant
August 12, 2019

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

try67
Community Expert
Community Expert
August 12, 2019

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.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 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)...

Mick2712Author
Participant
August 11, 2019

Hallo try67,

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

Viele Grüsse

Michael Kettner