Skip to content

Function: castValueAsDateTime() ​

ts
function castValueAsDateTime(value: unknown): DateTime;

Casts an unknown value to a Luxon DateTime with enhanced error handling and string parsing

Parameters ​

ParameterTypeDescription
valueunknownThe value to cast (string, number, Date, or DateTime)

Returns ​

DateTime

The value as a Luxon DateTime

Throws ​

E_UNCASTABLE when the value cannot be cast to a DateTime

Remarks ​

For string values, attempts SQL format parsing first, then falls back to ISO format parsing