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

# TryJulianDateToDateTime

A Julian date (or Julian Day) is a number that refers to the number of days, including fractional days, that have elapsed since a particular historical point in time. The current Julian cycle started at Greenwich noon on January 1, 4713 B.C. (Gregorian calendar), and will end on January 22, 3268 A.D.

Julian date is commonly used by astronomers, geophysicists, and others, and used in computer science to calculate the difference between days, since all numbers in the system are consecutive integers.

For example, the Julian date for December 11, 1942 is 2430705; while December 12, 1942 is 2430706.

This function **TryJulianDateToDateTime** attempts to convert a Julian Date into its corresponding **TDateTime** value, and tests whether a valid **TDateTime** value would be generated.

**TryJulianDateToDateTime** returns **True** if it can successfully convert **AValue** to a **TDateTime** value, and returns **False** if it cannot convert **AValue** into a **TDateTime** value.

**Declaration**: function TryJulianDateToDateTime(const AValue: Double; out ADateTime: TDateTime): Boolean;

Here is an easy example, with one intentional failed result.

```pascal
procedure OnMapEvent(var Value:Variant);
var
  TheDate : TDateTime;
  TheJDate : double;
  aGo : boolean;
begin

 //Returns 'The Julian 2460284.5 is 06-12-2023 00:00:00.000'
  TheJDate := 2460284.5;
  aGo := TryJulianDateToDateTime(TheJDate, TheDate);
 If aGo = True then
    LogInfo('The Julian '+FloatToStr(TheJDate)+' is '+FormatDateTime('dd-mm-yyyy hh:nn:ss.zzz', TheDate))
 else
    LogInfo ('Sorry - not a valid attempt.');

 //Returns 'Sorry - not a valid attempt.'
  TheJDate := 246;
  aGo := TryJulianDateToDateTime(TheJDate, TheDate);
 If aGo = True then
    LogInfo('The Julian '+FloatToStr(TheJDate)+' is '+FormatDateTime('dd-mm-yyyy hh:nn:ss.zzz', TheDate))
 else
    LogInfo ('Sorry - not a valid attempt.');

 //Returns 'The Julian 2430706.59 is 13-12-1942 02:09:36.000'
  TheJDate := 2430706.59;
  aGo := TryJulianDateToDateTime(TheJDate, TheDate);
 If aGo = True then
    LogInfo('The Julian '+FloatToStr(TheJDate)+' is '+FormatDateTime('dd-mm-yyyy hh:nn:ss.zzz', TheDate))
 else
    LogInfo ('Sorry - not a valid attempt.');

end;
```
