Custom Date Formatting
2 minutes to readIf you want to display date and time in a unique format, you can customize the formatting of these values by using dedicated notation. The notation differs based on whether you want to include only a single date or time element in one field, or many elements in one field.
Multiple-segment notation
Symbol | Meaning | Example |
---|---|---|
d | Day as 1-31 | d-MMM-yy = 6-Jan-23 |
dd | Day as 01-31 | MMMM dd = January 06 |
ddd | Day as Mon-Sun | ddd, MMMM dd, yyyy = Fri, January 06, 2023 |
dddd | Day as Monday-Sunday | dddd, M/d/yy = Friday, 1/6/23 |
M | Month as 1-12 | M/d/yy = 1/6/23 |
MM | Month as 01-12 | MM/yyyy = 01/2023 |
MMM | Month as Jan-Dec | d MMM yyyy = 6 Jan 2023 |
MMMM | Month as January-December | MMMM d = January 6 |
yy | Year as 00-99 | d MMM yy = 6 Jan 23 |
yyyy | Year as 2000-9999 | MMM dd, yyyy = Jan 06, 2023 |
h | Hour as 0-12 | h:mm:ss = 1:07:08 |
hh | Hour as 00-12 | hh:mm:ss tt = 01:07:08 PM |
H | Hour as 0-23 | H:mm = 9:07 |
HH | Hour as 00-23 | HH:mm = 13:07 |
m | Minute as 1-59 | m:ss = 7:08 |
mm | Minute as 01-59 | d-MMM-yy h:mm:ss = 6-Jan-23 1:07:08 |
s | Second as 1-59 | h:m:s = 1:7:8 |
ss | Second as 01-59 | dddd, M/d/yy h:mm:ss = Friday, 1/6/23 1:07:08 |
t | A/P | hh:mm:ss t = 01:07:08 P |
tt | AM/PM | MMMM dd, hh:mm tt = January 06, 01:07 PM |
Single-segment notation
Symbol | Meaning | Example |
---|---|---|
%d | Day as 1-31 | %d = 6 |
dd | Day as 01-31 | dd = 06 |
ddd | Day as Mon-Sun | ddd = Tue |
dddd | Day as Monday-Sunday | dddd = Tuesday |
%M | Month as 1-12 | %M = 1 |
MM | Month as 01-12 | MM = 01 |
MMM | Month as Jan-Dec | MMM = Jan |
MMMM | Month as January-December | MMMM = January |
yy | Year as 00-99 | yy = 09 |
yyyy | Year as 2000-9999 | yyyy = 2009 |
%h | Hour as 0-12 | %h = 1 |
hh | Hour as 00-12 | hh = 01 |
%H | Hour as 0-23 | %H = 13 |
HH | Hour as 00-23 | HH = 13 |
%m | Minute as 1-59 | %m = 9 |
mm | Minute as 01-59 | mm = 09 |
%s | Second as 1-59 | %s = 7 |
ss | Second as 01-59 | ss = 07 |
%t | A/P | %t = P |
tt | AM/PM | tt = PM |
Standard date and time format strings
You can also use single-letter notation to display predefined date and time formats based on standard date and time format strings. The following table shows examples of such standard format strings:
Symbol | Meaning | Example |
---|---|---|
d | Short date | d = 6/6/2023 |
M | Month and day | M = June 6 |
y | Month and year | y = June 2009 |
m | Month and day | m = June 29 |
s | Sortable date and time | s = 2023-06-06T13:15:47 |
t | Short time | t = 1:15 PM |