Von |
Peter258 |
Am |
01. Februar 2009 um 11:09:18 |
Frage |
Hallo,
ich wollte eine Funktion erstellen die den Abstand zwischen zwei Datumsangaben möglichst sprechend wiedergibt, z.B. 3 Jahre 2 Monate 9 Stunden 8 Minuten 10 Sekunden. Leider klappt das überhaupt nicht.
Wenn ich die Funktion aufrufe, kommen die komischten Sachen raus.
funGetDatediff("30.01.2009 11:10:05","01.02.2009 12:00:05")Public Function funGetDatediff(ByVal dteDatum1 As Date, ByVal dteDatum2 As Date) Dim dteDifferenz As Date Dim strDatum As String dteDifferenz = dteDatum2 - dteDatum1 strDatum = "" If CLng(Format(dteDifferenz, "yyyy")) - 1900 > 0 Then strDatum = strDatum & Round(Format(dteDifferenz, "yyyy") - 1900, 0) & " Jahr(e) " If CLng(Format(dteDifferenz, "mm")) > 0 Then strDatum = strDatum & Round(Format(dteDifferenz, "mm"), 0) & " Monat(e) " If CLng(Format(dteDifferenz, "dd")) > 0 Then strDatum = strDatum & Round(Format(dteDifferenz, "dd"), 0) & " h " If CLng(Format(dteDifferenz, "hh")) > 0 Then strDatum = strDatum & Round(Format(dteDifferenz, "hh"), 0) & " d " If CLng(Format(dteDifferenz, "nn")) > 0 Then strDatum = strDatum & Round(Format(dteDifferenz, "nn"), 0) & " min " If CLng(Format(dteDifferenz, "ss")) > 0 Then strDatum = strDatum & Round(Format(dteDifferenz, "ss"), 0) & " sec " funGetDatediff = strDatum End Function Ich finde den Fehler leider nicht und hoffe auf eure Tipps. Peter |
|