Skip to content

Function: castValueAsDate()

ts
function castValueAsDate(value: unknown): DateTime;

Casts an unknown value to a Luxon DateTime with enhanced 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