Skip to content

formatDate

The formatDate function converts date inputs into various formatted string representations based on the specified format parameter.

{date | formatDate:format:locale}
  • input (string/Date): A date string or Date object to format
  • format (string): The desired output format
  • locale (string, optional): A BCP 47 language tag used for translated month and weekday names. Defaults to en-US
FormatOutput ExampleDescription
"Month"”January”Month name only
"Month Year"”January 2024”Month name and year
"Day Month Year"”15 January 2024”Full date with month name
"DD/MM/YYYY"”15/01/2024”Numeric date with slashes
"YYYY"”2024”Year only
  • Formatted date string based on the specified format
  • Returns input unchanged if undefined or format not recognized
{"2024-01-15" | formatDate:"Month"}
// Returns: "January"
{"2024-03-20" | formatDate:"Month Year"}
// Returns: "March 2024"
{"2024-12-25" | formatDate:"Day Month Year"}
// Returns: "25 December 2024"
{"2024-07-04" | formatDate:"DD/MM/YYYY"}
// Returns: "04/07/2024"
{project.created_at | formatDate:"YYYY"}
// Returns: "2024"
{report.created_at | formatDate:"d. F Y":"de-DE"}
// Returns: "23. Juni 2026"
{report.created_at | formatDate:"l, d. F Y":"de-DE"}
// Returns: "Dienstag, 23. Juni 2026"
{report.created_at | formatDate:"d. F Y":"en-US"}
// Returns: "23. June 2026"
{report.created_at | formatDate:"d. F Y":"fr-FR"}
// Returns: "23. juin 2026"
{assessment.start_date | formatDate:"Day Month Year"}
// Returns formatted assessment start date

Pass a locale as the third argument when the output should use translated month or weekday names.

The locale must be a valid BCP 47 language tag, such as:

  • de-DE: German
  • en-US: American English
  • en-GB: British English
  • fr-FR: French
  • es-ES: Spanish
  • hr-HR: Croatian

If no locale is provided, en-US is used. Invalid locales also fall back to en-US.

CharacterDescriptionGerman example
DShort weekday nameDi
lFull weekday nameDienstag
FFull month nameJuni
MShort month nameJun
dDay with leading zero23
jDay without leading zero23
mNumeric month with leading zero06
nNumeric month without leading zero6
YFour-digit year2026
yTwo-digit year26

Only textual month and weekday values are affected by the locale. Numeric values remain unchanged.

  • Report generation with formatted dates
  • Creating human-readable timestamps
  • Standardizing date display across documents
  • Executive summaries with month/year only
  • International date formatting
  • Uses en-US when no locale is provided or when the provided locale is invalid
  • UTC timezone is used for “Day Month Year” format to avoid timezone issues
  • Returns undefined if input is undefined (safe for missing data)