joely
asked on
WeekOfYear
How can I know what week is the date in a year ?
Ex. January 1, 1998 : 1st week
December 28, 1998 : 52th week
Ex. January 1, 1998 : 1st week
December 28, 1998 : 52th week
Try this:
procedure TForm1.Button1Click(Sender : TObject);
var
CurrentDate, Year, Jan1, Week :string;
Days :integer;
begin
CurrentDate := DateToStr(Now);
Year := copy(CurrentDate, Length(CurrentDate)-1,2);
Jan1 := '1/1/'+Year;
Days := Trunc(Now-StrToDate(Jan1)) ;
Str((Days div 7)+1, Week);
Panel1.Caption := Week;
end;
procedure TForm1.Button1Click(Sender
var
CurrentDate, Year, Jan1, Week :string;
Days :integer;
begin
CurrentDate := DateToStr(Now);
Year := copy(CurrentDate, Length(CurrentDate)-1,2);
Jan1 := '1/1/'+Year;
Days := Trunc(Now-StrToDate(Jan1))
Str((Days div 7)+1, Week);
Panel1.Caption := Week;
end;
actually now that I look at the link bruintje mentioned, the code there takes into account the day of the week Jan 1 falls on..
If you are using the RXlib, then you can find that function in the dateutils unit.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Take a look at this link,
http://www.ellipse-data.com/delphifaq/delphi_faq_1.html#2.5.8.2
there is a function called week of year on the page.
Bruintje.