DayOfWeek (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example uses an edit box and a button on a form. When the user enters a date in the edit box in the format associated with the current locale (for example MM/DD/YY format in the US), the string entered is converted to a TDateTime value. This value is used to indicate the day of the week the date represents.

Code

procedure TForm1.Button1Click(Sender: TObject);
var
  ADate: TDateTime;
  days: array[1..7] of string;
begin
  days[1] := 'Sunday';
  days[2] := 'Monday';
  days[3] := 'Tuesday';
  days[4] := 'Wednesday';
  days[5] := 'Thursday';
  days[6] := 'Friday';
  days[7] := 'Saturday';
  ADate := StrToDate(Edit1.Text);
  ShowMessage(Edit1.Text + ' is a ' + days[SysUtils.DayOfWeek(ADate)]);
end;

Uses

Personal tools
Assistance