Skip to content

ToDate

cartographer


cartographer / toDate

toDate(value): Date | null

Defined in: types/types.ts:32

Safely convert a value to a Date. Returns the Date if possible, otherwise returns null.

unknown

Any value that might be a date

Date | null

  • Date object if conversion succeeds, null otherwise
const date1 = toDate('2026-01-06'); // Returns: Date object
const date2 = toDate(1704844800000); // Returns: Date object (timestamp)
const date3 = toDate('invalid'); // Returns: null