Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# WeekOfYear

Posted on 1998-12-04
Medium Priority
638 Views
How can I know what week is the date in a year ?

Ex. January 1, 1998   : 1st week

December 28, 1998 : 52th week
0
Question by:joely
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 44

Expert Comment

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

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

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

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

Accepted Solution

Alex_K earned 40 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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
###### Suggested Courses
Course of the Month9 days, 15 hours left to enroll