The RecodeDate function selectively replaces the date portions of a specified TDateTime value.

The function converts the date/time TDateTime value specified by AValue, with the value obtained by changing the year to the value of AYear, the month to the value of AMonth, and the day to value of ADay.

  • AYear must range from 1 through 9999 inclusive.

  • AMonth must be a valid month from 1 through 12 inclusive.

  • Valid accepted values for ADay range from 1 to 31, and are dependent on the number of valid days available within the month specified by AMonth. For instance, you could not specify ADay as 30 for the month of February.

If the value provided for any parameter is not within the allowable range, then RecodeDate raises an exception error.

Declaration: Function RecodeDate(const AValue: TDateTime; const AYear, AMonth, ADay: Word): TDateTime;

An example would be as follows.

procedure OnMapEvent(var Value:Variant);
var
TheDate, ThatDate : TDateTime;
aYear, aMonth, aDay : word;
begin
aYear := 2023;
aMonth := 12;
aDay := 3;
TheDate := EncodeDateTime(2024, 06, 25, 00, 00, 00, 000);
//If Date is 2024-06-25 then the result is 2023-12-03
ThatDate := RecodeDate(TheDate, aYear, aMonth, aDay);
LogInfo(FormatDateTime('dd-mm-yyyy hh:nn:ss.zzz', ThatDate));
 
//This will produce an error - February does not have 30 days
aYear := 2023;
aMonth := 2;
aDay := 30;
ThatDate := RecodeDate(TheDate, aYear, aMonth, aDay);
LogInfo(FormatDateTime('dd-mm-yyyy hh:nn:ss.zzz', ThatDate));
end;