hallo miteinander,
hab eine frage, die bestimmt so grundlegend ist, dass sie mir jeder beantworten kann. bestimmt ist mein code sowieso so wirsch, dass er garnicht funktionieren kann. aber ich brauche dringend hilfe, danke im voraus schomma.
ich brauche zwei funktionen, um zwei datumswerte miteinander vergleichen zu können. sicher, da gibts comparedate und so, aber ich brauche als result nur, ob datum1 vor datum2 und ob datum1 nach datum2 ist. als typ sollte result boolean haben.
bisher hab ich folgendes zusammengeschustert:
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
| function isbefore(date1,date2 : tdate) : boolean; var y1,y2,d1,d2,m1,m2 : word; begin decodedate(date1,y1,m1,d1); decodedate(date2,y2,m2,d2); if y1<y2 then result:=true; if (m1<m2) and (y1<y2+1) then result := true; if (d1<d2+1) and (m1<m2+1) and (y1<y2+1) then result := true; end;
function isafter(date1,date2 : tdate) : boolean; var y1,y2,y3,d1,d2,d3,m1,m2,m3 : word; begin decodedate(date1,y1,m1,d1); decodedate(date2,y2,m2,d2); if y1>y2 then result:=true; if (m1>m2) and (y1>y2-1) then result := true; if (d1>d2-1) and (m1>m2-1) and (y1>y2-1) then result := true; end; |
dabei wird bei IsBefore geprüft, ob date1 vor date2 ist und
bei IsAfter wird geprüft, ob date1 nach date2 ist.
beim ausprobieren mit folgendem code ist date1 vor UND nach date2...
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8:
| procedure TForm1.FormCreate(Sender: TObject); var date1,date2 : tdate; begin date1:=strtodate('01.01.2003'); date2:=strtodate('02.02.2003'); if isbefore(date1,date2) then showmessage('date1 is vor date2'); if isafter(date1,date2) then showmessage('date1 is nach date2'); end; |
folgerung: es funktioniert nicht. dass mein code wirsch aufgebaut ist, teilweise dinge unnötig sind, ist mir schon klar. ist eh nur kurz dahingefetzt, weil ich unter zeitdruck bin. also bin ich für schnelle und konstruktive hilfe dankbar!
Moderiert von
DeCodeGuru: Code- durch Delphi-Tags ersetzt