[fpc-pascal]date handling routines

Gabor DEAK JAHN djg at tramontana.co.hu
Thu Aug 30 23:25:33 CEST 2001


At 8/30/01 01:46 PM, you wrote:

Matt,

 > Wondering if there was already a unit available that could tell me the day
 > of week a certain date was.  An example perhaps would be:

There is one such function in the SysUtils unit already but here you have
the implementation of the original and famous Zeller closed-formula
algorithm (Zeller was a mathematician way before the computer era). The
wonderful part is that it doesn't need a table to know the length of the
individual months but uses a multiplication and a division to calculate
it... It returns 0 for Saturday, 1 for Sunday, 2 for Monday, etc. The
formula is universal, it works across all centuries.

function Date2DOW (Y, D, M : cardinal) : cardinal;
var
   Century : cardinal;
begin
   Century := Y div 100;
   Y := Y mod 100;
   if M < 3 then
     begin dec (Y); inc (M, 12); end;
   Date2DOW := (((M + 1) * 26 div 10) + D + Y + (Y div 4) + (Century div 4) 
- 2 * Century) mod 7;
end;


Bye,
    Gábor

-------------------------------------------------------------------
Gabor DEAK JAHN -- Budapest, Hungary.
The Citroën BX Do-It-Yourself Site (with XM Pages): 
www.tramontana.co.hu/citroen
E-mail: djg at tramontana.co.hu





More information about the fpc-pascal mailing list