1. Home
  2. Computing & Technology
  3. Delphi Programming

Week number calculating

By , About.com Guide

Here's how to calculate a week-of-the-year index (0-51) for a given date. Week 0 is the week containing the first Sunday of the year.

~~~~~~~~~~~~~~~~~~~~~~~~~
function WeekNum(const TDT:TDateTime) : Word;
var
  Y,M,D:Word;
  dtTmp:TDateTime;
begin
  DecodeDate(TDT,Y,M,D) ;
  dtTmp := EnCodeDate(Y,1,1) ;
  Result :=
    (Trunc(TDT-dtTmp)+(DayOfWeek(dtTmp)-1)) DIV 7;
  if Result <> 0 then Result := Result - 1;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Create new program group in the Start menu
« Standard Dialogs: changing default button title

Explore Delphi Programming
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2000 Delphi Tips
  7. Week number calculating

©2010 About.com, a part of The New York Times Company.

All rights reserved.