Here is an example of how to get the dates of a given week number. See the comments for an example of the usage. procedure GetDates(iWeekNbr: integer; var dSunday, dSaturday: TDateTime);
{ proc to extract the week dates from Sunday to Saturday of a given week number. }
{ Code can be modified to return Monday to Friday if needed. }
{ Example:
procedure TForm1.Button1Click(Sender: TObject);
var
Sunday, Saturday: TDateTime;
begin
GetDates(23, Sunday, Saturday);
ShowMessage(DateToStr(Sunday) + ' - ' + DateToStr(Saturday));
end; } var
dYear, dMonth, dDay: word;
TempDate: TDateTime;
begin
DecodeDate(now, dYear, dMonth, dDay);
{ get the date for the first day of the year. }
TempDate := EncodeDate(dYear, 1, 1);
{ get the date for the first Sunday - 1st full week } while DayOfWeek(TempDate) <> 1 do
TempDate := TempDate + 1;
{ get the Sunday for the specified week. }
dSunday := TempDate + (7*(iWeekNbr-1));
{ get the following Saturday. }
dSaturday := dSunday + 6;
end;