---
url: >-
  /statelake/scripting-reference/functions-and-procedures/datetime-functions/tryrecodedatetime.md
---

# TryRecodeDateTime

The **TryRecodeDateTime** function calculates the **TDateTime** value that is represented by the specified parameters, and tests whether a valid **TDateTime** value would be generated from those specified individual parts. **TryRecodeDateTime** returns **True** if the parameters are all in a valid range, and returns **False** if any parameter is not within the allowable range.

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.

**Declaration**: Function TryRecodeDateTime(const AValue: TDateTime; const AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond: Word; out AResult: TDateTime): Boolean;

An example would be as follows.

```pascal
procedure OnMapEvent(var Value:Variant);
var
  TheDate, bDate, bDate1 : TDateTime;
  aYear, aMonth, aDay, aHour, aMin, aSec, aMil : word;
  aGo := boolean;
begin
  aYear := 2023;
  aMonth := 12;
  aDay := 3;
  aHour := 20;
  aMin := 20;
  aSec := 30;
  aMil := 500;
  TheDate := EncodeDateTime(2024, 06, 25, 00, 00, 00, 000);
  LogInfo(FormatDateTime('dd-mm-yyyy hh:nn:ss.zzz', TheDate));
 //If Date is 2024-06-25 then the result is 2023-12-03 - returns True
  aGo := TryRecodeDateTime(TheDate, aYear,  aMonth, aDay, aHour, aMin, aSec, aMil, bDate);
 If aGo = True then
    LogInfo('The date works - '+FormatDateTime('dd-mm-yyyy hh:nn:ss.zzz', bDate))
 else
    LogInfo('The date DOES NOT work - '+FormatDateTime('dd-mm-yyyy hh:nn:ss.zzz', bDate));

  aYear := 2023;
  aMonth := 2;
  aDay := 30;
  aHour := 20;
  aMin := 20;
  aSec := 30;
  aMil := 500;
 //This will produce an error - February does not have 30 days - returns False
  aGo := TryRecodeDateTime(TheDate, aYear,  aMonth, aDay, aHour, aMin, aSec, aMil, bDate1);
 If aGo = True then
    LogInfo('The date works - '+FormatDateTime('dd-mm-yyyy hh:nn:ss.zzz', bDate1))
 else
    LogInfo('The date DOES NOT work - '+FormatDateTime('dd-mm-yyyy hh:nn:ss.zzz', bDate1));

end;
```
