Board index » delphi » SIMPLE question: Week numbers

SIMPLE question: Week numbers

Is it possible to retrieve the current week number in Delphi?
I've browsed the date/time routines section but can't find the solution.
 

Re:SIMPLE question: Week numbers


JRS:  In article <4O7%5.215$V76.6...@news.get2net.dk> of Sun, 17 Dec
2000 19:42:13 seen in news:alt.comp.lang.borland-delphi, Jimmy Rasmussen

Quote
<jim...@get2net.dk> wrote:
>Is it possible to retrieve the current week number in Delphi?
>I've browsed the date/time routines section but can't find the solution.

I fear that it is not quite so simple a question as all that; Delphi,
being an American product, might not use the same definition of Week
Number as we in the EU do, if it had Week Numbers.

For Week Number definitions (ISO-8601, and UK Inland Revenue) see Web
<URL: http://www.merlyn.demon.co.uk/moredate.htm>.

For Week Number code, written for BP7 & Delphi 3, see PAS, EXE in <URL:
http://www.merlyn.demon.co.uk/programs/> (use <URL: http://www.merlyn.de
mon.co.uk/programs/00index.htm>) for

        dateprox.pas - source
        version.pas - needed
        mjd_date.pas - demonstrates the above
        mjd_date.exe
        mjd_date.zip

The first contains several week number routines, for ISO-8601 &
otherwise.  NOTE that the first and last weeks can overlap into the
adjacent calendar year, so watch for year number changes.

ISO-8601 weeks are Monday..Sunday.  ISO-8601 Week 1 is the week which
contains January 4; the week which contains the first Thursday; the
first week mainly within the calendar year.

See js-dates.htm to do it in javascript.

For next year, from <URL: http://www.merlyn.demon.co.uk/week-cal.txt>,
ISO weeks :

 Year Mo   Weeks Mon-Sun
 2001 Jan  #01    01--07  08--14  15--21  22--28  29-
 2001 Feb  #05       -04  05--11  12--18  19--25  26-
 2001 Mar  #09       -04  05--11  12--18  19--25  26-
 2001 Apr  #13       -01  02--08  09--15  16--22  23--29  30-
 2001 May  #18       -06  07--13  14--20  21--27  28-
 2001 Jun  #22       -03  04--10  11--17  18--24  25-
 2001 Jul  #26       -01  02--08  09--15  16--22  23--29  30-
 2001 Aug  #31       -05  06--12  13--19  20--26  27-
 2001 Sep  #35       -02  03--09  10--16  17--23  24--30
 2001 Oct  #40    01--07  08--14  15--21  22--28  29-
 2001 Nov  #44       -04  05--11  12--18  19--25  26-
 2001 Dec  #48       -02  03--09  10--16  17--23  24--30  31-

HTH

--
? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
 Web <URL: http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
 PAS, EXE in <URL: http://www.merlyn.demon.co.uk/programs/> - see 00index.txt.
 Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm  &c.

Re:SIMPLE question: Week numbers


I always use the following code (credits go to hoever posted this earlier):

var
  FirstWeekDay: Integer = 2; { first day of week
    2 : monday (DIN 1355) }
  FirstWeekDate: Integer = 4; { date in first week
    1 : year starts on Jan 1st
    4 : first "4-day-week" (DIN 1355)
    7 : first complete week }

{ Returns date of first day of week }
function WeekToDate(AWeek, AYear: Integer): TDateTime;
begin
  Result := EncodeDate(AYear, 1, FirstWeekDate);
  Result := Result + (AWeek - 1) * 7 - ((DayOfWeek(Result) + (7 -
FirstWeekDay)) mod 7);
end;

{ Returns no. of week and year the week belongs to }
procedure DateToWeek(ADate: TDateTime; var AWeek, AYear: Integer);
var
  Month, Day: Word;
begin
  ADate := ADate - ((DayOfWeek(ADate) - FirstWeekDay + 7) mod 7) + 7 -
FirstWeekDate;
  DecodeDate(ADate, AYear, Month, Day);
  AWeek := (Trunc(ADate - EncodeDate(AYear, 1, 1)) div 7) + 1;
end;

"Jimmy Rasmussen" <jim...@get2net.dk> schreef in bericht
news:4O7%5.215$V76.6003@news.get2net.dk...

Quote
> Is it possible to retrieve the current week number in Delphi?
> I've browsed the date/time routines section but can't find the solution.

Other Threads