[fpc-pascal]Week Day

Full_Name memsom at post.interalpha.net
Thu Apr 19 10:12:21 CEST 2001


Quoting Rich Pasco <pasco at acm.org>:

Simpler to understand? (also Delphi based)

function StrWeekday(D,M,Y: word): string;
var
  DT: TDate;
begin
  Result := FormatDateTime('dddd', EncodeDate(Y, M, D));
end;

Who said it had to be optomised ;)

Matt

> No assembler is required; it's easily done in Pascal:
> 
> function Weekday(D,M,Y: word): word;
>   (* Input D=day (1..31), M=month(1..12), Y=year(e.g. 2001) *)
>   (* Returns 0=Sunday, 1=Monday, ... 6=Saturday *)
>   const
>     FD: array[1..12] of byte = (6,2,2,5,0,3,5,1,4,6,2,4);
>   var
>     Y1: integer;
>   begin
>     if M > 2 then Y1 := Y else Y1 := Y-1;
>     WeekDay := ((D+(Y1 div 4)-(Y1 div 100)+(Y1 div 400)+Y+FD[M]) mod
> 7);
>   end;




More information about the fpc-pascal mailing list