Solved

WeekOfYear

Posted on 1998-12-04
5
621 Views
Last Modified: 2012-06-21
How can I know what week is the date in a year ?

Ex. January 1, 1998   : 1st week
       
      December 28, 1998 : 52th week
0
Comment
Question by:joely
5 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 1349355
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
 
LVL 5

Expert Comment

by:scrapdog
ID: 1349356
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
 
LVL 5

Expert Comment

by:scrapdog
ID: 1349357
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
 
LVL 4

Expert Comment

by:jeurk
ID: 1349358
If you are using the RXlib, then you can find that function in the dateutils unit.
0
 

Accepted Solution

by:
Alex_K earned 10 total points
ID: 1349359
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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now