Registriert seit: 25. Jun 2003
Ort: Thüringen
2.950 Beiträge
|
Re: Start- und Enddatum einer Kalenderwoche ermitteln
15. Dez 2003, 16:29
Delphi-Quellcode:
function WeekOfDate(ADate: TDateTime): Integer;
var
Day: Integer;
Y,M,D: Word;
begin
Day := DayOfWeekGerman(ADate);
DecodeDate(ADate +4 -Day, Y, M, D);
Result := Round(((ADate +8 -Day) - EncodeDate(Y, 1, 1)) / 7);
end;
function DateOfWeek(AYear, AWeek: Word): TDateTime;
begin
Result := EncodeDate(AYear, 1, 1);
Result := Result - (DayOfWeek(Result -2) +3) mod 7 +3 + (AWeek -1) * 7;
end;
function WeeksOfYear(AYear: Word): Integer;
var
D: TDateTime;
begin
D := EncodeDate(AYear+1, 1, 1); // 1.1. des folgenden Jahres
Result := WeekOfDate(D); // KW
if Result = 1 then
begin
D := D - 7; // 1 KW zurück
Result := WeekOfDate(D);
end;
end;
function DayOfWeekGerman(ADate: TDateTime): Integer;
begin
Result := DayOfWeek(ADate) -1;
if Result <= 0 then Result := 7;
end;
function WeekStart(ADate: TDateTime; German: Boolean): TDateTime;
begin
if German then Result := ADate - (DayOfWeekGerman(ADate) -1)
else Result := ADate - (DayOfWeek(ADate) -1);
end;
WeekOfDate() ist die Funktion die du suchst.
Gruß Hagen
|
|
Zitat
|