Description
The function formatDate
returns the specified date formatted according to the given pattern. It allows you to format a date using predefined placeholders to display it in the desired format.
Various placeholders can be used to structure the date in different formats, such as for day, month, year, hour, minute, and more.
Syntax
formatDate(date, format)
Arguments
Argument | Description |
---|---|
date |
The date to be formatted. |
format |
The format in which the date should be returned. Various formatting options can be used, such as day, month, year, hour, etc. |
Formatting Options
The following formatting options are available:
Format | Description |
---|---|
d |
Day of the month (1-31). |
dd |
Day of the month (01-31). |
ddd |
Abbreviated weekday name (e.g., "Mon"). |
dddd |
Full weekday name (e.g., "Monday"). |
h |
Hour (1-12). |
hh |
Hour (01-12). |
H |
Hour (0-23). |
HH |
Hour (00-23). |
m |
Minute (0-59). |
mm |
Minute (00-59). |
M |
Month (1-12). |
MM |
Month (01-12). |
MMM |
Abbreviated month name (e.g., "Jan"). |
MMMM |
Full month name (e.g., "January"). |
s |
Second (0-59). |
ss |
Second (00-59). |
t |
AM/PM indicator (one character). |
tt |
AM/PM indicator. |
y |
Year (0-99). |
yy |
Year (00-99). |
yyy |
Year. |
yyyy |
Year. |
Examples
Description | Formula |
---|---|
Formatting a date in "dd.MM.yyyy" format |
formatDate("2024-12-25", "dd.MM.yyyy")Result: 25.12.2024 |
Formatting a date in "dd-MMM-yyyy" format |
formatDate("2024-12-25", "dd-MMM-yyyy")Result: 25-Dec-2024 |
Formatting the weekday (abbreviated) |
formatDate("2024-12-25", "ddd")Result: Wed |
Formatting the hour in 24-hour format |
formatDate("2024-12-25T15:30:00", "HH:mm")Result: 15:30 |
Notes
- The format can be customized by combining different placeholders as needed.
- The function cannot be persisted using
persist
. - Ensure that the date is correctly formatted to obtain the desired results.
Comments
0 comments
Please sign in to leave a comment.