RecodeDateTime
The RecodeDateTime function selectively replaces 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, the hour to AHour, the minute to AMinute, the second to ASecond, and the millisecond to AMilliSecond.
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.
AHour can be a value from 0 to 23 inclusive.
AMinute can range from 0 through to 59 inclusive.
ASecond can range from 0 through to 59 inclusive.
AMilliSecond value can range from 0 through to 999 inclusive.
If the value provided for any parameter is not within the allowable range, then RecodeDateTime raises an exception error.
Declaration: Function RecodeDateTime(const AValue: TDateTime; const AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond: Word): TDateTime;
An example would be as follows.
procedure
OnMapEvent(
var
Value:Variant);
var
TheDate, ThatDate : TDateTime;
aYear, aMonth, aDay, aHour, aMin, aSec, aMil :
word
;
begin
aYear :=
2023
;
aMonth :=
12
;
aDay :=
3
;
aHour :=
20
;
aMin :=
20
;
aSec :=
30
;
aMil :=
500
;
TheDate := EncodeDateTime(
2024
,
06
,
25
,
00
,
00
,
00
,
000
);
//If Date is 2024-06-25 then the result is 2023-12-03
ThatDate := RecodeDateTime(TheDate, aYear, aMonth, aDay, aHour, aMin, aSec, aMil);
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
;
aHour :=
20
;
aMin :=
20
;
aSec :=
30
;
aMil :=
500
;
ThatDate := RecodeDateTime(TheDate, aYear, aMonth, aDay, aHour, aMin, aSec, aMil);
LogInfo(FormatDateTime(
'dd-mm-yyyy hh:nn:ss.zzz'
, ThatDate));
end
;