formatDate
The formatDate function converts date inputs into various formatted string representations based on the specified format parameter.
Syntax
Section titled “Syntax”{date | formatDate:format:locale}Parameters
Section titled “Parameters”input(string/Date): A date string or Date object to formatformat(string): The desired output formatlocale(string, optional): A BCP 47 language tag used for translated month and weekday names. Defaults toen-US
Supported Formats
Section titled “Supported Formats”| Format | Output Example | Description |
|---|---|---|
"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 |
Returns
Section titled “Returns”- Formatted date string based on the specified format
- Returns input unchanged if undefined or format not recognized
Examples
Section titled “Examples”Month only
Section titled “Month only”{"2024-01-15" | formatDate:"Month"}// Returns: "January"Month and year
Section titled “Month and year”{"2024-03-20" | formatDate:"Month Year"}// Returns: "March 2024"Full date
Section titled “Full date”{"2024-12-25" | formatDate:"Day Month Year"}// Returns: "25 December 2024"Numeric format
Section titled “Numeric format”{"2024-07-04" | formatDate:"DD/MM/YYYY"}// Returns: "04/07/2024"Year only
Section titled “Year only”{project.created_at | formatDate:"YYYY"}// Returns: "2024"Localized month name
Section titled “Localized month name”{report.created_at | formatDate:"d. F Y":"de-DE"}// Returns: "23. Juni 2026"Localized weekday
Section titled “Localized weekday”{report.created_at | formatDate:"l, d. F Y":"de-DE"}// Returns: "Dienstag, 23. Juni 2026"Other locales
Section titled “Other locales”{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"Report dates
Section titled “Report dates”{assessment.start_date | formatDate:"Day Month Year"}// Returns formatted assessment start dateLocalized Date Formatting
Section titled “Localized Date Formatting”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: Germanen-US: American Englishen-GB: British Englishfr-FR: Frenches-ES: Spanishhr-HR: Croatian
If no locale is provided, en-US is used. Invalid locales also fall back to en-US.
Relevant format characters
Section titled “Relevant format characters”| Character | Description | German example |
|---|---|---|
D | Short weekday name | Di |
l | Full weekday name | Dienstag |
F | Full month name | Juni |
M | Short month name | Jun |
d | Day with leading zero | 23 |
j | Day without leading zero | 23 |
m | Numeric month with leading zero | 06 |
n | Numeric month without leading zero | 6 |
Y | Four-digit year | 2026 |
y | Two-digit year | 26 |
Only textual month and weekday values are affected by the locale. Numeric values remain unchanged.
Use Cases
Section titled “Use Cases”- 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-USwhen 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)