Skip to content

shortDate()

ts
function shortDate(date?: Date): string | undefined;

Formats a given date to a short date string which is used e.g. in datetime element attributes.

Parameters

date?

Date = ...

The date to format. Defaults to the current date.

Returns

string | undefined

A string in the format 'YYYY-MM-DD'.

Example

ts
shortDate(new Date(2025, 6, 12)) // '2025-07-12'