[fpc-pascal]date handling routines
James_Wilson at i2.com
James_Wilson at i2.com
Thu Aug 30 20:58:54 CEST 2001
> 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:
Try passing this function a packed longint and it should return the
weekday in a 0..6 sequence, with 0 being Sunday. Note I didn't compile
this so it might need to be tweaked. :-)
Jim
Function DayOfWeek (DateToCheck : longint) : byte
const
FileDays : array[1..12] of byte = (6,2,2,5,0,3,5,1,4,6,2,4);
var
DateAndTime : datetime;
AdjustedYear : integer;
begin
unpacktime (DateToCheck,DateAndTime);
// leap year adjustment
if DateAndTime.month > 2 then AdjustedYear := DateAndTime.year else
AdjustedYear := pred (DateAndTime.year);
WeekDay := ((DateAndTime.day + (AdjustedYear div 4) - (AdjustedYear div
100) + (AdjustedYear div 400) + DateAndTime.year + FileDays
[DateAndTime.month]) mod 7);
end;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20010830/b9ddbbae/attachment.html>
More information about the fpc-pascal
mailing list