- 16 Apr 2024
- 4 Minutes to read
- DarkLight
Format Strings
- Updated on 16 Apr 2024
- 4 Minutes to read
- DarkLight
General
Format strings are used when converting a number or date-time to a string (textual) representation with a given format.
Example: The number 1256 can be converted to a string in the format 1.256 where the dot is a group separator with the format string #.##0.
Number Format Strings
A full description of format strings that may be used when converting numbers to strings can be found in the Standard Numeric Format Strings and Custom Numeric Format Strings articles of the .NET language reference.
Standard Numeric Format Strings
These format strings are used to format a number to a format defined in the regional settings of the operating system in which Mail & Deploy runs (i.e. the Windows culture settings). The following table contains a few examples of standard numeric format strings:
Format String | Description |
---|---|
C | Formats the number as a currency with the number of decimals and currency symbol as defined in the currently active culture settings. You can override the default number of decimals by appending the number of required decimals after the C (e.g. C3 will format the currency with 3 decimals). |
P | Formats the number as a percentage by multiplying it with 100 and displaying a % symbol. |
X | Formats the number as a hexa-decimal string. |
Custom Numeric Format Strings
These format strings allow a more detailed control over how a number is formatted. They can be constructed from the following placeholders:
Placeholder | Description |
---|---|
0 | The zero placeholder will be replaced by the actual digit of the formatted number if one is present; otherwise a zero appears in the result string. |
# | The # placeholder will be replaced by the actual digit of the formatted number if one is present; otherwise, no digit appears in the result string. |
. | The decimal placeholder can be used to specify the location of the decimal separator in the result string. The placeholder to be used is always a dot and is independent of the active culture settings, which will only affect the decimal separator used in the result string. |
, | The comma placeholder can be used to specify the location of the group separator in the result string. The placeholder to be used is always a comma and is independent of the active culture settings, which will only affect the group separator used in the result string. |
The following example formats a number to always show to decimals and at least one digit before the decimal. Groups of digits before the decimal will be separated using the group separator of the active culture settings:
#,##0.00
The following example formats a number to always show three digits but no decimals:
000
Date-Time Format Strings
A full description of format strings that may be used when converting date-times to strings can be found in the Standard Date and Time Format Strings and Custom Date and Time Format Strings articles of the .NET language reference.
Standard Numeric Format Strings
These format strings are used to format a date-time to a format defined in the regional settings of the operating system in which Mail & Deploy runs (i.e. the Windows culture settings). The following table contains a few examples of standard date-time format strings:
Format String | Description |
---|---|
d | Formats the date-time using the short date pattern (e.g. 6/15/2009 for US culture settings). |
D | Formats the date-time using the long date pattern (e.g. Monday, June 15, 2009 for US culture settings). |
f | Formats the date-time using the full date-time pattern with short time (e.g. Monday, June 15, 2009 1:45 PM for US culture settings). |
F | Formats the date-time using the full date-time pattern with long time (e.g. Monday, June 15, 2009 1:45:30 PM for US culture settings). |
Custom Date-Time Format Strings
These format strings allow a more detailed control over how a date-time is formatted. They can be constructed from the following placeholders:
Placeholder | Description |
---|---|
d | This placeholder will be replaced by the number of the day (e.g. 1 or 30) either as a single digit or two digits. |
dd | This placeholder will be replaced by the number of the day (e.g. 01 or 30) with two digits. |
M | This placeholder will be replaced by the month from 1 to 12 (e.g. 1 or 11) either as a single digit or two digits. |
MM | This placeholder will be replaced by the month from 1 to 12 (e.g. 01 or 11) with two digits. |
yyyy | This placeholder will be replaced by the year with four digits. |
h | This placeholder will be replaced by the hour from 1 to 12 (e.g. 1 or 11) either as a single digit or two digits. |
hh | This placeholder will be replaced by the hour from 1 to 12 (e.g. 01 or 11) with two digits. |
H | This placeholder will be replaced by the hour from 1 to 24 (e.g. 1 or 11) either as a single digit or two digits. |
HH | This placeholder will be replaced by the hour from 1 to 24 (e.g. 01 or 11) with two digits. |
m | This placeholder will be replaced by the minute from 1 to 59 (e.g. 1 or 11) either as a single digit or two digits. |
mm | Th.is placeholder will be replaced by the minute from 1 to 59 (e.g. 01 or 11) with two digits. |
tt | This placeholder will be replaced by either AM or PM. |
: | This placeholder will be replaced by the time-separator of the current culture settings. |
/ | This placeholder will be replaced by the date-separator of the current culture settings. |
The following example format string formats the date to show two day digits, two month digits, and four year digits:
MM/dd/yyyy
The following example format string formats the date-time to show two day digits, two month digits, four year digits, 2 hour digits (1 to 24), and 2 minute digits:
MM/dd/yyyy HH:mm