Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 649
  • Last Modified:

WeekOfYear

How can I know what week is the date in a year ?

Ex. January 1, 1998   : 1st week
       
      December 28, 1998 : 52th week
0
joely
Asked:
joely
1 Solution
 
bruintjeCommented:
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.
0
 
scrapdogCommented:
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;

0
 
scrapdogCommented:
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..
0
 
jeurkCommented:
If you are using the RXlib, then you can find that function in the dateutils unit.
0
 
Alex_KCommented:
You must get date_ in TDateTime type like
date_:=now;
in next step you must truncate this variable like
date_:=trunc(date_);
and last step, is calculated number of day of week:
day:=(date_ mod 7)-2;

It all...

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now