Format

Applies a formatting rule to a string or numeric value. For example, you can change the format of an ISO 8601 timestamp to show the date in the format that you prefer.

Format(1, 2)

OrdinalTypeDescription
1String or numberRequired. The string or number to apply a formatting rule to.
2StringRequired. A format code to apply to the string.

Use these codes to format numeric values or strings that contain numeric values. The values in the Example column are based on a sample numeric value of 4213.65.

Formatting CodeDescriptionExample
CCurrency value with group and decimal separators$4,213.65
DDecimal value4213.65
EExponential notation value4.213650E+003
FFixed-point value4213.65
GThe more compact of either fixed-point or exponential notation4213.65
NNumber with group and decimal separators4,213.65
PPercentage with group and decimal separators421,365.00%

Include a number after any formatting code to modify the number of decimal places in the output, rounding up or down as needed. For example, if the input value is 4213.65 and you specify the C0 formatting code, the output value is $4,214. With the same starting value and a formatting code of C4, the output value becomes $4,213.6500.

To apply a formatting rule to a date, specify the format that you want the function to output. You can use a predefined date format or specify a custom date format.

This table lists the predefined date formats for date values. The values in the Example column are based on the date Monday, August 5, 2024 at 1:41:23 PM in the UTC-06:00 time zone.

Formatting CodeDescriptionExample
dShort-form date8/5/24
MMonth and dayAugust 5
fLong-form date with 12-hour timeMonday, August 5, 2024 1:41 PM
gShort-form date with 12-hour time8/5/2024 1:41 PM
OISO 8601 timestamp2024-08-05T13:41:23.0000000
rRFC 1123 timestampMon, 05 Aug 2024 13:41:23 GMT
sSortable timestamp2024-08-05T13:41:23
t12-hour time1:41 PM
T12-hour time in seconds1:41:23 PM
uUniversal sortable timestamp2024-08-05 13:41:23Z
ULong-form date with 12-hour UTC time in secondsMonday, August 5, 2024 7:41:23 PM
yMonth and yearAugust 2024

Combine the format codes listed in this table to output a date string that uses a custom format. The values in the Example column are based on the date Monday, August 5, 2024 at 1:41:23 PM in the UTC-06:00 time zone.

Formatting CodeDescriptionExample
dDay expressed as a numeral without a leading zero5
ddDay expressed as a numeral05
dddAbbreviated day nameMon
ddddDay nameMonday
hHours on a 12-hour clock without a leading zero1
hhHours on a 12-hour clock01
HHHours on a 24-hour clock13
mmMinutes41
MMonth expressed as a numeral without a leading zero8
MMMonth expressed as a numeral08
MMMAbbreviated month nameAug
MMMMMonth nameAugust
ssSeconds23
tt12-hour time period (AM or PM)PM
yyLast two digits of the year24
yyyYear2024
zTime zone offset in hours without a leading zero-6
zzTime zone offset in hours-06
zzzTime zone offset in hours and minutes-06:00

Some format codes for custom dates are the same as the codes for predefined date formats. When you pass a single formatting code as a parameter for the Format function, the function outputs a date string in the specified format. If you pass more than one formatting code as a parameter, the function outputs a string with the date-formatting options you specified. For example, using the same example timestamp that’s used in the table, the function Format(date, "d") outputs 8/5/24. However, the function Format(date, "d MMMM") outputs 5 August.

You can use this function to format strings in several different ways. These examples show some of the ways that you can use this function.

Use the C formatting code to express a string or number as a currency value. The function in this example specifies that the output includes two decimal places (C2).

The function outputs the string expressed as a dollar amount rounded to two decimal places.

This example shows how to format a date by using a predefined format and a custom format.

This example uses the O formatting code to format the incoming date and time value as an ISO timestamp. Next, it uses a custom format for the incoming date and time. The custom format includes the full name of the day (dddd), the full name of the month (MMMM), the date without a leading zero (d), and the year (yyy). It also shows the time in 24-hour format, including hours, minutes, seconds, and UTC offset (HH:mm:ss (zzz)).

The function outputs the date and time using the specified formats.