TryJulianDateToDateTime
Function TryJulianDateToDateTime(const AValue: Double;
var ADateTime: TDateTime): Boolean
Example
procedure ScriptEvent(var Value: variant);
var
EncodedValue: TDateTime;
begin
if TryJulianDateToDateTime(2451545.0, EncodedValue) then
Value := EncodedValue; // 1 January 2000 at 12:00
end;
Usage
TryJulianDateToDateTime tries to convert an astronomical Julian date into an encoded Gregorian date and millisecond time.
Parameters
| Name | Type | Description |
|---|---|---|
AValue | Double, const | Julian date number including its noon-based fractional day. |
ADateTime | TDateTime, var | Receives the converted value when the calendar part is encodable. |
Returns
True when the derived Gregorian year/month/day can be encoded; otherwise normally False. Numeric and post-encode failures are not comprehensively caught.
Behaviour
2451545.0maps to 1 January 2000 at 12:00.- Adding
0.5advances twelve hours to the following midnight. - Output is an untagged calendar value; the routine does not retain an astronomical time scale such as UTC or TT.
Errors
Unencodable calendar fields normally return False. Numeric conversion, overflow or timestamp errors can still propagate.
Additional Technical Info
TryJulianDateToDateTime converts an astronomical Julian date number to Delphi's proleptic-Gregorian TDateTime. Julian integral-day boundaries occur at noon, and the conversion reduces the fractional day to millisecond resolution.
The example is fictional, deterministic and source-reviewed. It was not executed by the documentation workflow.
Implementation
The DateUtils import binds directly to Delphi 37.0 System.DateUtils.TryJulianDateToDateTime. The terminal:
- applies
Truncand integer Gregorian-calendar conversion arithmetic; - casts the derived fields to
Wordand callsTryEncodeDate; - converts
Abs(Frac(AValue))to a millisecond-within-day value; - subtracts 12 hours for the Julian noon boundary; and
- adds the fractional milliseconds with DateUtils timestamp arithmetic.
Edge cases and quirks
- The result is limited by Delphi's encodable years
1..9999. An unencodable derived date normally returnsFalsewithout assigningADateTime. - The
Trycontract covers the date-encode decision, not every floating/integer operation. NaN, infinity or extreme magnitudes can raise duringTrunc, integer arithmetic or later timestamp increments instead of returningFalse. - Fractional input is quantised through
MilliSecondOfTheDay; sub-millisecond detail is lost and binary floating-point approximation applies. - The implementation uses the absolute fractional magnitude. Negative/extreme Julian values should not be extrapolated without confirming the supported convention and range.
- Near the supported date boundaries, the subsequent 12-hour and millisecond adjustments are not wrapped in a second Boolean validation.
Side effects
May write ADateTime; no shared state or I/O.
Performance and concurrency
Constant-time floating-point, integer and timestamp arithmetic with no shared mutable state.
Related entries
JulianDateToDateTimeraises a conversion exception when this routine returnsFalse.TryModifiedJulianDateToDateTimeapplies the Modified Julian offset first.DateTimeToJulianDateperforms the inverse conversion.
External references
Created 2026-07-15