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


Calculating week number ?

Posted on 1999-07-12
Medium Priority
Last Modified: 2008-02-01
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?
Question by:tonitop
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
  • Learn & ask questions
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;
  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
  if dow <> 3 then
    if Result = 0 then
      Result := WeekNumber(EncodeDate(year - 1, 12, 31))
    else if Result = 53 then
      Result := WeekNumber(EncodeDate(year + 1, 1, 1));



Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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:…
Suggested Courses

715 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