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:
Output
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.