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

x
Solved

# Calculating week number ?

Posted on 1999-07-12
Medium Priority
752 Views
I've made a Delphi function that counts the number of week using given date as a parameter. Is it possible to determine the last week's number? (Is it 52 or 53?) Is there any component or function available that would do this job?
0
Question by:tonitop
[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
1 Comment

LVL 13

Accepted Solution

Epsylon earned 200 total points
ID: 1387777
The function below calculates the weeknumber of a given date. Notice that the weeknumber depends on what is the first day of the week.

function WeekNumber(TheDate: TDateTime): Word;
var year, month, day, dow: Word;
d: TDateTime;
begin
DecodeDate(TheDate, year, month, day);
d := EncodeDate(year, 1, 1);
dow := DayOfWeek(d) - 1;
Result := (Round(TheDate - d) + dow) div 7;
if dow <= 3 then
Inc(Result);
if dow <> 3 then
begin
if Result = 0 then
Result := WeekNumber(EncodeDate(year - 1, 12, 31))
else if Result = 53 then
Result := WeekNumber(EncodeDate(year + 1, 1, 1));
end;
end;

Epsylon.

0

## Featured Post

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
###### Suggested Courses
Course of the Month7 days, 8 hours left to enroll