Zeit berechnen
Hallo
Ich habe 2 Datumsfelder, Geburtstag und Sterbetag.
Ich möchte berechnen wie lange die Person gelebt hat. Jahre, Monate und Tage.
Danke für die Hilfe
Rudi
2 Antworten
-
Hallo Rudolf,
vorausgesetzt, Du hast ein Feld BeginnDatum und ein Feld EndeDatum, dann kannst Du diesen Code verwenden (habe ich hier im Forum gefunden und ist nicht von mir, funktioniert hervorragend)
let DATUM1 := BeginnDatum;
let DATUM2 := EndeDatum;
if DATUM1 = null or DATUM2 = null then
""
else
let D1 := if DATUM1 > DATUM2 then DATUM2 else DATUM1 end;
let D2 := if DATUM1 > DATUM2 then DATUM1 else DATUM2 end;
let DD := if day(D2) >= day(D1) then
day(D2) - day(D1)
else
day(date(year(D1), month(D1) + 1, 1) - 1) - day(D1) + day(D2)
end;
let MM := if month(D1) <= month(D2) then
month(D2) - month(D1)
else
12 - month(D1) + month(D2)
end;
let MMM := if day(D2) >= day(D1) then
MM
else
if MM = 0 then 11 else MM - 1 end
end;
let YY := if month(D2) > month(D1) then
year(D2) - year(D1)
else
if month(D2) < month(D1) then
year(D2) - year(D1) - 1
else
if day(D1) <= day(D2) then
year(D2) - year(D1)
else
year(D2) - year(D1) - 1
end
end
end;
if DATUM1 = null then
""
else
if YY = 0 then
""
else
if YY = 1 then
YY + " Jahr" + if MMM = 0 and DD = 0 then "" else ", " end
else
YY + " Jahre" + if MMM = 0 and DD = 0 then "" else ", " end
end
end +
if MMM = 0 then
""
else
if MMM = 1 then
MMM + " Monat" + if DD = 0 then "" else ", " end
else
MMM + " Monate" + if DD = 0 then "" else ", " end
end
end +
if DD = 0 then
""
else
if DD = 1 then DD + " Tag" else DD + " Tage" end
end
end
end
Content aside
- vor 1 JahrZuletzt aktiv
- 2Antworten
- 53Ansichten
-
2
Folge bereits