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}Parameters
Section titled “Parameters”input(string/Date): A date string or Date object to formatformat(string): The desired output format
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 |
| (other) | Original input | Returns input unchanged |
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"Report dates
Section titled “Report dates”{assessment.start_date | formatDate:"Day Month Year"}// Returns formatted assessment start dateUse 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 browser’s locale settings for month names (defaults to en-US)
- UTC timezone is used for “Day Month Year” format to avoid timezone issues
- Returns undefined if input is undefined (safe for missing data)