From RAD Studio API Documentation
Jump to: navigation, search


function TryEncodeDateMonthWeek(const AYear, AMonth, AWeekOfMonth,
ADayOfWeek: Word; var AValue: TDateTime): Boolean;


extern DELPHI_PACKAGE bool __fastcall TryEncodeDateMonthWeek(const System::Word AYear, const System::Word AMonth, const System::Word AWeekOfMonth, const System::Word ADayOfWeek, System::TDateTime &AValue);


Type Visibility Source Unit Parent
function public
System.DateUtils System.DateUtils


Calculates the TDateTime value that represents a specified day of a specified week in a specified month and year.

TryEncodeDateMonthWeek calculates the TDateTime value for the date specified by the AYear, AMonth, AWeekOfMonth, and ADayOfWeek parameters.

AYear is the year. It can be any value from 1 through 9999 (inclusive).

AMonth is the month. It can be any value from 1 through 12 (inclusive).

AWeekOfMonth is the week within that month, where 1 is the first week that includes four or more days. Note that, if the first calendar day of the month is a Friday, Saturday, or Sunday, then those three days must be expressed using AMonth set to the previous month and AWeekOfMonth set to the number of weeks in the previous month. Similarly, if the last calendar day of the month is a Monday, Tuesday, or Wednesday, then those three days are expressed with AMonth set to the following month and AWeekOfMonth set to 1.

ADayOfWeek is the day of the week, where 1 is Monday, 2 is Tuesday, and so on.

AValue returns the specified date as a TDateTime value. The time portion of AValue is 0 (midnight at the start of the specified day).

TryEncodeDateMonthWeek returns True if AYear, AMonth, AWeekOfMonth, and ADayOfWeek represent a valid date, and False if any of these parameters are not in the valid range.

Note: The definitions for AWeekOfYear and ADayOfWeek follow the ISO 8601 standard.

Tip: To make the ADayOfWeek value more readable, use the day of week constants.

See Also

Code Examples