SmartPascal
DayOfTheWeek
Function
Gives day of week index for a TDateTime value (ISO 8601) DateUtils unit
 function DayOfTheWeek ( const Date : TDateTime ) : Integer;
Description
The DayOfTheWeek function returns an index number for the day of the week :
= Monday
= Tuesday
= Wednesday
= Thursday
= Friday
= Saturday
= Sunday
Notes
DayOfTheWeek is ISO 8601 compliant, since it uses Monday as the start of the week.

DayOfWeek is not compliant - it treats Sunday as the starting day.
Related commands
DayOfTheMonth Gives day of month index for a TDateTime value (ISO 8601)
DayOfTheYear Gives the day of the year for a TDateTime value (ISO 8601)
DayOfWeek Gives day of week index for a TDateTime value
MonthOfTheYear Gives the month of the year for a TDateTime value
 
Example code : Show the day of the week for Christmas 2002
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
 
unit Unit1;
 
interface
 
uses
  DateUtils,   // Unit containing the DayOfTheWeek command
  SysUtils,
  Forms, Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;
 
var
  
Form1: TForm1;
 
implementation
{$R *.dfm} // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);

var
  myDate : TDateTime;
  day    : array[1..7] of string;

begin
  // We cannot use LongDayNames - they start on Sunday
  day[1] := 'Monday';
  day[2] := 'Tuesday';
  day[3] := 'Wednesday';
  day[4] := 'Thursday';
  day[5] := 'Friday';
  day[6] := 'Saturday';
  day[7] := 'Sunday';

  myDate := EncodeDate(2002, 12, 25);

  ShowMessage('Christmas day 2002 is on a '+day[DayOfTheWeek(myDate)]);
end;
 
end.
Hide full unit code
   Christmas day 2002 is on a Wednesday