Mega Code Archive

 
Categories / Delphi / Functions
 

Dayoftheweek - 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 : 1 = Monday 2 = Tuesday 3 = Wednesday 4 = Thursday 5 = Friday 6 = Saturday 7 = 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 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; Show full unit code Christmas day 2002 is on a Wednesday