Custom Date and Time formats for the FORMAT Function

Custom Date and Time formats for the FORMAT Function

 

The following table shows characters you can use to create user-defined date/time formats.

Format specificationDescription
(:)Time separator. In some locales, other characters may be used to represent the time separator. The time separator separates hours, minutes, and seconds when time values are formatted. The actual character that is used as the time separator in formatted output is determined by your application's current culture value.
(/)Date separator. In some locales, other characters may be used to represent the date separator. The date separator separates the day, month, and year when date values are formatted. The actual character that is used as the date separator in formatted output is determined by your application's current culture.
(%)Used to indicate that the following character should be read as a single-letter format without regard to any trailing letters. Also used to indicate that a single-letter format is read as a user-defined format. See what follows for additional details.
dDisplays the day as a number without a leading zero (for example, 1). Use %d if this is the only character in your user-defined numeric format.
ddDisplays the day as a number with a leading zero (for example, 01).
dddDisplays the day as an abbreviation (for example, Sun).
ddddDisplays the day as a full name (for example, Sunday).
MDisplays the month as a number without a leading zero (for example, January is represented as 1). Use %M if this is the only character in your user-defined numeric format.
MMDisplays the month as a number with a leading zero (for example, 01/12/01).
MMMDisplays the month as an abbreviation (for example, Jan).
MMMMDisplays the month as a full month name (for example, January).
ggDisplays the period/era string (for example, A.D.).
hDisplays the hour as a number without leading zeros using the 12-hour clock (for example, 1:15:15 PM). Use %h if this is the only character in your user-defined numeric format.
hhDisplays the hour as a number with leading zeros using the 12-hour clock (for example, 01:15:15 PM).
HDisplays the hour as a number without leading zeros using the 24-hour clock (for example, 1:15:15). Use %H if this is the only character in your user-defined numeric format.
HHDisplays the hour as a number with leading zeros using the 24-hour clock (for example, 01:15:15).
mDisplays the minute as a number without leading zeros (for example, 12:1:15). Use %m if this is the only character in your user-defined numeric format.
mmDisplays the minute as a number with leading zeros (for example, 12:01:15).
sDisplays the second as a number without leading zeros (for example, 12:15:5). Use %s if this is the only character in your user-defined numeric format.
ssDisplays the second as a number with leading zeros (for example, 12:15:05).
fDisplays fractions of seconds. For example ff displays hundredths of seconds, whereas ffff displays ten-thousandths of seconds. You may use up to seven f symbols in your user-defined format. Use %f if this is the only character in your user-defined numeric format.
tUses the 12-hour clock and displays an uppercase A for any hour before noon; displays an uppercase P for any hour between noon and 11:59 P.M. Use %t if this is the only character in your user-defined numeric format.
ttFor locales that use a 12-hour clock, displays an uppercase AM with any hour before noon; displays an uppercase PM with any hour between noon and 11:59 P.M.

For locales that use a 24-hour clock, displays nothing.
yDisplays the year number (0-9) without leading zeros. Use %y if this is the only character in your user-defined numeric format.
yyDisplays the year in two-digit numeric format with a leading zero, if applicable.
yyyDisplays the year in four-digit numeric format.
yyyyDisplays the year in four-digit numeric format.
zDisplays the timezone offset without a leading zero (for example, -8). Use %z if this is the only character in your user-defined numeric format.
zzDisplays the timezone offset with a leading zero (for example, -08)
zzzDisplays the full timezone offset (for example, -08:00)

Remarks

Formatting strings are case sensitive. Different formatting can be obtained by using a different case. For example, when formatting a date value with the string "D" you get the date in the long format (according to your current locale). However, if you change the case to "d" you get the date in the short format. Also, unexpected results or an error might occur if the intended formatting does not match the case of any defined format string.

Date/Time formatting uses the current user locale to determine the ultimate format of the string. For example, to format the date March 18, 1995, with the following format string "M/d/yyyy", if the user locale is set to the United States of America (en-us) the result is '3/12/1995', but if the user locale is set to Germany (de-de) the result is '18.03.1995'.

See Also

FORMAT Function (DAX)
Custom Numeric Formats for the FORMAT Function
Pre-defined Date and Time formats for the FORMAT Function

Community Additions

ADD
Show:
© 2016 Microsoft