Question and Answer Database FAQ1822D.txt How can I determine the week number of a given day in the year? Category :Miscellaneous Platform :All Product :All 32 bit Question: How can I determine the week number of a given day in the year? Answer: This is a highly debated subject, as the first week of the year may be considered to be before or after Jan 1. The following function provides a starting point for WeekOfYear calculations. Example: function WeekOfYear(ADate : TDateTime) : word; var day : word; month : word; year : word; FirstOfYear : TDateTime; begin DecodeDate(ADate, year, month, day); FirstOfYear := EncodeDate(year, 1, 1); Result := Trunc(ADate — FirstOfYear) div 7 + 1; end; procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage(IntToStr(WeekOfYear(Date))); end; 7/16/98 4:31:28 PM
Last Modified: 01-SEP-99