So hier mal meine Lösung ...
Code: Alles auswählen
DataSection
MonthDays:
Data.i 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
EndDataSection
Procedure MonthDays(Date)
Protected Days
Days = PeekI(?MonthDays+SizeOf(Integer)*Month(Date))
If Month(Date) = 2
If Not Year(Date) % 4 : Days + 1 : EndIf
If Not Year(Date) % 100 : Days - 1 : EndIf
If Not Year(Date) % 400 : Days + 1 : EndIf
EndIf
ProcedureReturn Days
EndProcedure
Procedure.s SubDate(Date1, Date2)
Protected Text.s
Protected Year, Month, Day, Hour, Minute, Second
If Date1 < Date2
Swap Date1, Date2 : Text = "- "
EndIf
Year = Year(Date1)-Year(Date2)
Month = Month(Date1)-Month(Date2)
Day = Day(Date1)-Day(Date2)
Hour = Hour(Date1)-Hour(Date2)
Minute = Minute(Date1)-Minute(Date2)
Second = Second(Date1)-Second(Date2)
If Second < 0 : Second = 60+Second : Minute - 1 : EndIf
If Minute < 0 : Minute = 60+Minute : Hour - 1 : EndIf
If Hour < 0 : Hour = 24+Hour : Day - 1 : EndIf
If Day < 0 : Day = MonthDays(Date2)+Day : Month - 1 : EndIf
If Month < 0 : Month = 12+Month : Year - 1 : EndIf
Text + Str(Year)+" Jahr(e) "
Text + Str(Month)+" Monat(e) "
Text + Str(Day)+" Tag(e) "
Text + Str(Hour)+" Stunde(n) "
Text + Str(Minute)+" Minute(n) "
Text + Str(Second)+" Sekunde(n) "
ProcedureReturn Text
EndProcedure
Debug SubDate(Date(2011,03,27,0,0,0), Date(2011,02,28,0,0,0)) ; Februar
Debug SubDate(Date(2008,03,27,0,0,0), Date(2008,02,28,0,0,0)) ; Februar , Schaltjar
Debug SubDate(Date(2008,03,27,0,0,0), Date(2008,01,28,0,0,0)) ; Januar , Schaltjar egal
Debug SubDate(Date(2008,02,02,0,0,0), Date(2011,02,01,0,0,0)) ; negativ , Februar , Schaltjar