Lebensalter berechnen
<script language="javascript" type="text/javascript"><!-- [et_pb_line_break_holder] --><!-- <!-- [et_pb_line_break_holder] -->function reset() {<!-- [et_pb_line_break_holder] --> document.rechner.gebdat.value = "";<!-- [et_pb_line_break_holder] --> document.rechner.ergebnis.value = "";<!-- [et_pb_line_break_holder] -->}<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->function round(wert, dez) {<!-- [et_pb_line_break_holder] --> wert = parseFloat(wert);<!-- [et_pb_line_break_holder] --> if (!wert) return 0;<!-- [et_pb_line_break_holder] --> dez = parseInt(dez);<!-- [et_pb_line_break_holder] --> if (!dez) dez=0;<!-- [et_pb_line_break_holder] --> var umrechnungsfaktor = Math.pow(10,dez);<!-- [et_pb_line_break_holder] --> return Math.round(wert * umrechnungsfaktor) / umrechnungsfaktor;<!-- [et_pb_line_break_holder] -->} <!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->function lebensalter(G_tag, G_monat, G_jahr)<!-- [et_pb_line_break_holder] -->{<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] --> var alter = 0;<!-- [et_pb_line_break_holder] --> var H_datum = new Date(); <!-- [et_pb_line_break_holder] --> var H_tag = H_datum.getDate();<!-- [et_pb_line_break_holder] --> var H_monat = H_datum.getMonth() + 1; // Month liefert 0-11<!-- [et_pb_line_break_holder] --> var H_jahr = H_datum.getFullYear();<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] --> alter = H_jahr - G_jahr; <!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] --> if (G_monat > H_monat) { <!-- [et_pb_line_break_holder] --> alter = alter - 1; <!-- [et_pb_line_break_holder] --> } <!-- [et_pb_line_break_holder] --> else if (G_monat == H_monat) {<!-- [et_pb_line_break_holder] --> if (G_tag > H_tag) { alter = alter - 1; }<!-- [et_pb_line_break_holder] --> }<!-- [et_pb_line_break_holder] --> <!-- [et_pb_line_break_holder] --> return alter;<!-- [et_pb_line_break_holder] -->}<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->function go() { <!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] --> var gebdat = document.rechner.gebdat.value;<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] --> if (gebdat.trim() == "") {<!-- [et_pb_line_break_holder] --> document.rechner.ergebnis.value = "Geburtsdatum eingeben"; <!-- [et_pb_line_break_holder] --> alert("Eingaben überprüfen."); <!-- [et_pb_line_break_holder] --> return;<!-- [et_pb_line_break_holder] --> }<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] --> gdarr = gebdat.split(".");<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] --> if (gdarr.length != 3) {<!-- [et_pb_line_break_holder] --> document.rechner.ergebnis.value = "Eingabe prüfen"; return;<!-- [et_pb_line_break_holder] --> }<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] --> var jahr = parseInt(gdarr[2]);<!-- [et_pb_line_break_holder] --> var monat = parseInt(gdarr[1]);<!-- [et_pb_line_break_holder] --> var tag = parseInt(gdarr[0]);<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] --> if ( (jahr < 1900) || (monat > 12) || (tag > 31) ) {<!-- [et_pb_line_break_holder] --> document.rechner.ergebnis.value = "Eingabe bitte prüfen"; return;<!-- [et_pb_line_break_holder] --> }<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] --> document.rechner.ergebnis.value = lebensalter(tag, monat, jahr);<!-- [et_pb_line_break_holder] -->}<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] -->//--><!-- [et_pb_line_break_holder] --></script>
Aktuelles Alter berechnen
Dieses kleine „Helferlein“ berechnet das aktuelle Alter aus dem Geburtsdatum.
<form action="" name="rechner"><!-- [et_pb_line_break_holder] --><table><!-- [et_pb_line_break_holder] --><tbody><!-- [et_pb_line_break_holder] --><tr><!-- [et_pb_line_break_holder] --><td>Geburtsdatum</td><!-- [et_pb_line_break_holder] --><td><input id="gebdat" name="gebdat" type="text"></td><!-- [et_pb_line_break_holder] --></tr><!-- [et_pb_line_break_holder] --><tr><!-- [et_pb_line_break_holder] --><td colspan="2"><input onclick="go()" style="background: #0058A2; color: white;" value="Berechnung" type="button"> <input onclick="reset()" style="background: #C4104A; color: white;" value="Zurücksetzen" type="button"></td><!-- [et_pb_line_break_holder] --></tr><!-- [et_pb_line_break_holder] --></tbody><!-- [et_pb_line_break_holder] --></table><!-- [et_pb_line_break_holder] --> <!-- [et_pb_line_break_holder] --><table><!-- [et_pb_line_break_holder] --><tbody><!-- [et_pb_line_break_holder] --><tr><!-- [et_pb_line_break_holder] --><td><!-- [et_pb_line_break_holder] --><h4>Ergebnis</h4><!-- [et_pb_line_break_holder] --></td><!-- [et_pb_line_break_holder] --></tr><!-- [et_pb_line_break_holder] --><tr><!-- [et_pb_line_break_holder] --><td>Aktuelles Lebensalter</td><!-- [et_pb_line_break_holder] --><td><input style="color: #333333; border: 1px solid #333333; font-size: 15px;" name="ergebnis" type="text"> Jahre</td><!-- [et_pb_line_break_holder] --></tr><!-- [et_pb_line_break_holder] --></tbody><!-- [et_pb_line_break_holder] --></table><!-- [et_pb_line_break_holder] --></form>