Format
This function formats a string in the specified format pattern and locale.
Format patterns follow the C# format types outlined in the official Microsoft documentation:
Some of these custom formats are supported:
Arguments
Format(1,2,3,4)
Ordinal | Type | Required | Description |
---|---|---|---|
1 | String | True | The string to format |
2 | String | True | The output format pattern (see table below for values) |
3 | String | False | Data format indicator. Valid values are Date and Number |
4 | String | False | The ISO locale code for the output |
Here are a few examples of format patterns, given a date of 2017-09-15T06:07:08.1230000-06:00
:
Element | Format Pattern | Output |
---|---|---|
Long Date | D |
Friday, September 15, 2017 |
Short date | d |
9/15/2017 |
Full Date, short time | f |
Friday, September 15, 2017 6:07 AM |
Full Date, long time | F |
Vendredi 15 Septembre 2017 06:07 |
General Date/Time, short time | g |
Friday, September 15, 2017 6:07:08 AM |
General Date/Time, long time | G |
9/15/2017 6:07 AM |
Month, Day | M or m |
September 15 |
Round Trip Date/Time | O or o |
2017-09-15T06:07:08.1230000-06:00 |
RFC1123 | R or r |
Fri, 15 Sep 2017 06:07:08 GMT |
Sortable Date/Time | s |
2017-09-15T06:07:08 |
Short Time | t |
6:07 AM |
Long Time | T |
6:07:08 AM |
Universal Sortable Date/Time | u |
2017-09-15 06:07:08Z |
Universal full Date/Time | U |
Friday, September 15, 2017 12:07:08 PM |
Month Year | Y |
September 2017 |
Month | MM |
09 |
Month | MMM |
Sep |
Month | MMMM |
September |
Day | dd |
15 |
Day | ddd |
Fri |
Day | ddddd |
Friday |
Hour | hh |
06 |
Minutes | mm |
07 |
Seconds | ss |
08 |
Milliseconds | MMM |
123 |
AM/PM | tt |
AM |
Timezone offset | zz |
-06 |
Timezone offset | zzz |
-06:00 |
NOTE: This function returns lowercase month and day names for non-US culture codes by default.
Here are a few examples of format patterns, given a number of -0.8967
:
Element | Format Pattern | Output |
---|---|---|
Currency | C or c |
($0.90) |
Decimal | D or d |
-0.8967 |
Exponential (scientific) | E or e |
-8.967000E-001 |
Fixed-point | F of f |
-0.90 |
General | G or g |
-0.8967 |
Number | N or n |
-0.90 |
Percent | P or p |
-89.67 % |
Here are a few examples of custom format patterns, given a number of -1.8967
:
Element | Format Pattern | Example | Output |
---|---|---|---|
Zero placeholder | 0 |
"0000" |
-0002 |
Digit placeholder | # |
"###0" |
-2 |
Decimal point | . |
"#0.00" |
-1.90 |
Group separator and scaling | , |
"0,00#.##" |
-0,001.9 |
Percentage placeholder | % |
"#.00%" |
-189.67% |
Exponential notation | E0 , E+0 , e0 or e+0 |
"#0.0e0" |
-19.0e-1 |
Escape character | \ |
"\###0.000\#" |
-#1.897# |
Literal string delimiter | 'string' or "string" |
"#.##' points'" |
-1.9 points |
Section separator | ; |
"#0.00;(#0.00)" |
(1.90) |
Example 1
The following examples illustrate the base date and time formats:
%%[
var @dateString, @timeString, @long, @short, @fullShortTime, @fullShortTimeFR, @fullLongTime, @generalShortTime, @generalLongTime, @monthDay, @roundTrip, @RFC1123, @sortable, @shortTime, @longTime, @universalSortable, @universalFull, @monthYear, @monthNumber, @monthShortName, @monthFullName, @dayNumber, @dayFullName, @hour, @minute, @seconds, @AMPM, @offsetHours, @offsetHoursMinutes
set @dateString = "2017-09-15T06:07:08.1230000-06:00"
set @timeString = "06:07:08.123 AM"
set @long = Format(@dateString,"D", "Date")
set @short = Format(@dateString,"d", "Date")
set @fullShortTime = Format(@dateString,"f", "Date")
set @fullShortTimeFR = ProperCase(Format(@dateString,"f", "Date","fr-FR"))
set @fullLongTime = Format(@dateString,"F", "Date")
set @generalShortTime = Format(@dateString,"g", "Date")
set @generalLongTime = Format(@dateString,"G", "Date")
set @monthDay = Format(@dateString,"M", "Date")
set @roundTrip = Format(@dateString,"O", "Date")
set @RFC1123 = Format(@dateString,"R", "Date")
set @sortable = Format(@dateString,"s", "Date")
set @shortTime = Format(@dateString,"t", "Date")
set @longTime = Format(@dateString,"T", "Date")
set @universalSortable = Format(@dateString,"u", "Date")
set @universalFull = Format(@dateString,"U", "Date")
set @monthYear = Format(@dateString,"Y", "Date")
set @monthNumber = Format(@dateString,"MM","Date")
set @monthShortName = Format(@dateString,"MMM","Date")
set @monthFullName = Format(@dateString,"MMMM","Date")
set @dayNumber = Format(@dateString,"dd","Date")
set @dayShortName = Format(@dateString,"ddd","Date")
set @dayFullName = Format(@dateString,"ddddd","Date")
set @hour = Format(@timeString,"hh","Date")
set @minute = Format(@timeString,"mm","Date")
set @seconds = Format(@timeString, "ss","Date")
set @AMPM = Format(@timeString,"tt","Date")
set @offsetHours = Format(@dateString,"zz","Date")
set @offsetHoursMinutes = Format(@dateString,"zzz","Date")
]%%
dateString: %%=v(@dateString)=%%
<br><br>long: %%=v(@long)=%%
<br>short: %%=v(@short)=%%
<br>fullShortTime: %%=v(@fullShortTime)=%%
<br>fullShortTimeFR: %%=v(@fullShortTimeFR)=%%
<br>fullLongTime: %%=v(@fullLongTime)=%%
<br>generalShortTime: %%=v(@generalShortTime)=%%
<br>generalLongTime: %%=v(@generalLongTime)=%%
<br>monthDay: %%=v(@monthDay)=%%
<br>roundTrip: %%=v(@roundTrip)=%%
<br>RFC1123: %%=v(@RFC1123)=%%
<br>sortable: %%=v(@sortable)=%%
<br>shortTime: %%=v(@shortTime)=%%
<br>longTime: %%=v(@longTime)=%%
<br>universalSortable: %%=v(@universalSortable)=%%
<br>universalFull: %%=v(@universalFull)=%%
<br>monthYear: %%=v(@monthYear)=%%
<br><br>monthNumber: %%=v(@monthNumber)=%%
<br>monthShortName: %%=v(@monthShortName)=%%
<br>monthFullName: %%=v(@monthFullName)=%%
<br>dayNumber: %%=v(@dayNumber)=%%
<br>dayShortName: %%=v(@dayShortName)=%%
<br>dayFullName: %%=v(@dayFullName)=%%
<br><br>timeString: %%=v(@timeString)=%%
<br>hour: %%=v(@hour)=%%
<br>minute: %%=v(@minute)=%%
<br>seconds: %%=v(@seconds)=%%
<br>AMPM: %%=v(@AMPM)=%%
<br>offsetHours: %%=v(@offsetHours)=%%
<br>offsetHoursMinutes: %%=v(@offsetHoursMinutes)=%%
Output
dateString: 2017-09-15T06:07:08.1230000-06:00
long: Friday, September 15, 2017
short: 9/15/2017
fullShortTime: Friday, September 15, 2017 6:07 AM
fullShortTimeFR: Vendredi 15 Septembre 2017 06:07
fullLongTime: Friday, September 15, 2017 6:07:08 AM
generalShortTime: 9/15/2017 6:07 AM
generalLongTime: 9/15/2017 6:07:08 AM
monthDay: September 15
roundTrip: 2017-09-15T06:07:08.1230000-06:00
RFC1123: Fri, 15 Sep 2017 06:07:08 GMT
sortable: 2017-09-15T06:07:08
shortTime: 6:07 AM
longTime: 6:07:08 AM
universalSortable: 2017-09-15 06:07:08Z
universalFull: Friday, September 15, 2017 12:07:08 PM
monthYear: September 2017
monthNumber: 09
monthShortName: Sep
monthFullName: September
dayNumber: 15
dayShortName: Fri
dayFullName: Friday
timeString: 06:07:08.123 AM
hour: 06
minute: 07
seconds: 08
AMPM: AM
offsetHours: -06
offsetHoursMinutes: -06:00
Example 2
The following examples illustrate some common number formats:
Not a subscriber? Subscribe now.
Example 3
The following examples illustrate some custom number formats:
Not a subscriber? Subscribe now.
Example 4
The following examples illustrate some common date formats:
Not a subscriber? Subscribe now.
Example 5
The following examples illustrate some common phone formats:
Not a subscriber? Subscribe now.