Registriert seit: 8. Jan 2008
73 Beiträge
Turbo Delphi für Win32
|
Re: Kalenderwoche Verständisproblem
3. Feb 2009, 17:31
Evtl. hilft Dir das weiter:
Delphi-Quellcode:
function DateToWeek(Datum:TDateTime; var Year:Word):Word;
var
Y,M,D : Word;
FDay : Word;
Days : Integer;
JanF : TDateTime;
begin
try
DecodeDate(Datum,Y,M,D);
Year:=Y;
JanF:=EncodeDate(Y,1,1);
FDay:=DayOfWeek(JanF);
Days:=Trunc(Int(Datum)-JanF)+(7-DayOfWeek(Datum-1))+(7*ord(FDay in [2..5]));
Result:=Days div 7;
if Result=0 then begin
if (DayOfWeek(EncodeDate(Y-1,1,1))>5) or (DayOfWeek(EncodeDate(y-1,12,31))<5) then
Result:=52
else
Result:=53;
Year:=Y-1;
end else
if Result=53 then begin
if (FDay>5) or (DayOfWeek(EncodeDate(Y,12,31))<5) then begin
Result:=1;
Year:=Y+1;
end;
end;
except
Result:=0;
end;
end;
|
|
Zitat
|