Link to home
Start Free TrialLog in
Avatar of joely
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
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Hi Joely,

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.
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;

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..
Avatar of jeurk
jeurk

If you are using the RXlib, then you can find that function in the dateutils unit.
ASKER CERTIFIED SOLUTION
Avatar of Alex_K
Alex_K

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial