Functions that work with date/time values all accept a format argument that determines how the date/time will be formatted.
Standard formats are single-character codes representing common date/time formats. Based on the code you enter, the date/time is formatted using the standard format for your locale.
For example, if you use the short date format @now("d") in the United States, this would be expanded to 1/23/2015, while in the United Kingdom it would be expanded to 2015/01/23.
If you want to make sure the value is formatted the same regardless of the language/locale of the computer, use a Custom Format as described below. For example, if you want you date to always appear as "1/23/2015" no matter where it is run, you would use @now("M/d/yyyy").
Format | Meaning | Example |
---|---|---|
d | Short date pattern. | 6/15/2014 |
D | Long date pattern. | Monday, June 15, 2014 |
f | Full date/time pattern (short time). | Monday, June 15, 2014 1:45 PM |
F | Full date/time pattern (long time). | Monday, June 15, 2014 1:45:30 PM |
g | General date/time pattern (short time). | 6/15/2014 1:45 PM |
G | General date/time pattern (long time). | 6/15/2014 1:45:30 PM |
M, m | Month/day pattern. | June 15 |
R, r | RFC1123 pattern. | Mon, 15 Jun 2014 20:45:30 GMT |
s | Sortable date/time pattern. | 2014-06-15T13:45:30 |
t | Short time pattern. | 1:45 PM |
T | Long time pattern. | 1:45:30 PM |
u | Universal sortable date/time pattern. | 2014-06-15 20:45:30Z |
U | Universal full date/time pattern. | Monday, June 15, 2014 8:45:30 PM |
Y, y | Year month pattern. | June, 2014 |
Custom formatting pattern is built up from tokens that represent parts of a date/time (year, month, day, hour, minute, second) in various formats.
Any character is not a special token is included without change.
For example, to format a date as "January 23, 2015" you would use the pattern MMMM d, yyyy.
The available tokens are described below. Note that tokens are case-sensitive: "M" represents a month, while "m" represents a minute.
If you want to use a single-character custom format to insert a part of a date/time, you must prefix the character with "%" so it does not get interpreted as a Standard Format (see above).
For example, if you use @now("d"), this will be expanded to 1/23/2015. If what you wanted was to insert just the day of the month without a leading 0, you would use @now("%d").
If your custom format string is longer than one character, this restriction does not apply.
Token | Meaning |
---|---|
d | The day of the month. Single-digit days will not have a leading zero (e.g., "1"). |
dd | The day of the month. Single-digit days will have a leading zero (e.g., "01"). |
ddd | The abbreviated name of the day of the week (e.g., "Wed"). |
dddd | The full name of the day of the week (e.g., "Wednesday"). |
M | The numeric month. Single-digit months will not have a leading zero. |
MM | The numeric month. Single-digit months will have a leading zero. |
MMM | The abbreviated name of the month (e.g., "Jan"). |
MMMM | The full name of the month (e.g., "January"). |
y | The year without the century. If the year without the century is less than 10, the year is displayed with no leading zero. |
yy | The year without the century. If the year without the century is less than 10, the year is displayed with a leading zero. |
yyyy | The year in four digits, including the century. |
gg | The period or era. This pattern is ignored if the date to be formatted does not have an associated period or era string. E.g., "BC" or "AD". |
h | The hour in a 12-hour clock. Single-digit hours will not have a leading zero. |
hh | The hour in a 12-hour clock. Single-digit hours will have a leading zero. |
H | The hour in a 24-hour clock. Single-digit hours will not have a leading zero. |
HH | The hour in a 24-hour clock. Single-digit hours will have a leading zero. |
m | The minute. Single-digit minutes will not have a leading zero. |
mm | The minute. Single-digit minutes will have a leading zero. |
s | The second. Single-digit seconds will not have a leading zero. |
ss | The second. Single-digit seconds will have a leading zero. |
t | The first character in the AM/PM designator. |
tt | The AM/PM designator. |
z | The time zone offset ("+" or "-" followed by the hour only). Single-digit hours will not have a leading zero. For example, Pacific Standard Time is "-8". |
zz | The time zone offset ("+" or "-" followed by the hour only). Single-digit hours will have a leading zero. For example, Pacific Standard Time is "-08". |
zzzz | The full time zone offset ("+" or "-" followed by the hour and minutes). Single-digit hours and minutes will have leading zeros. For example, Pacific Standard Time is "-08:00". |
: | The default time separator defined for the locale. |
/ | The default date separator defined for the locale. |