ToText method (date)
Returns this date as a text representation, using the specified format.
Syntax
date.ToText date.ToText(format)
Returns the text representation of date as specified by format.
format: A standard or custom date format.
The default value for format is 'G'.
Standard date formats
| Format specifier | Description | Examples (for en-GB culture) | |
|---|---|---|---|
| 'd' | Short date pattern | 2011-06-17 14:35:20 -> 17/06/2011 | |
| 'D' | Long date pattern | 2011-06-17 14:35:20 -> 17 June 2011 | |
| 'f' | Full date/time pattern (short time) | 2011-06-17 14:35:20 -> 17 June 2011 14:35 | |
| 'F' | Full date/time pattern (long time) | 2011-06-17 14:35:20 -> 17 June 2011 14:35:20 | |
| 'g' | General date/time pattern (short time) | 2011-06-17 14:35:20 -> 17/06/2011 14:35 | |
| 'G' | General date/time pattern (long time) | 2011-06-17 14:35:20 -> 17/06/2011 14:35:20 | |
| 'M' or 'm' | Month/day pattern | 2011-06-17 14:35:20 -> 17 June | |
| 'O' or 'o' | Round-trip date/time pattern | 2011-06-17 14:35:20 -> 2011-06-17T14:35:20.0000000 | |
| 'R' or 'r' | RFC1123 pattern | 2011-06-17 14:35:20 -> Fri, 17 Jun 2011 14:35:20 GMT | |
| 's' | Sortable date/time pattern | 2011-06-17 14:35:20 -> 2011-06-17T14:35:20 | |
| 't' | Short time pattern | 2011-06-17 14:35:20 -> 14:35 | |
| 'T' | Long time pattern | 2011-06-17 14:35:20 -> 14:35:20 | |
| 'u' | Universal sortable date/time pattern | 2011-06-17 14:35:20 -> 2011-06-17 14:35:20Z | |
| 'U' | Universal full date/time pattern | 2011-06-17 14:35:20 -> 17 June 2011 13:35:20 | |
| 'Y' or 'y' | Year month pattern | 2011-06-17 14:35:20 -> June 2011 | |
| Any other single character | Unknown | Causes a template error. |
Custom date formats
| Format specifier | Description | Examples (for en-GB culture) |
|---|---|---|
| 'd' | The day of the month, from 1 through 31. | 2011-06-17 14:35:20 -> 17 2011-06-07 14:35:20 -> 7 |
| 'dd' | The day of the month, from 01 through 31. | 2011-06-17 14:35:20 -> 17 2011-06-07 14:35:20 -> 07 |
| 'ddd' | The abbreviated name of the day of the week. | 2011-06-17 14:35:20 -> Fri 2011-06-07 14:35:20 -> Tue |
| 'dddd' | The full name of the day of the week. | 2011-06-17 14:35:20 -> Friday 2011-06-07 14:35:20 -> Tuesday |
| 'f', 'ff', 'fff', 'ffff', 'fffff', 'ffffff' or 'fffffff' | The fraction of a second. 'f' returns tenths of a second, 'fff' returns milliseconds and 'fffffff' returns 10 millionths of a second |
2011-06-17 14:35:20.718 (f) -> 7 2011-06-17 14:35:20.718 (ff) -> 71 2011-06-17 14:35:20.7185425 (fffffff) -> 7185425 |
| 'F', 'FF', 'FFF', 'FFFF', 'FFFFF', 'FFFFFF' or 'FFFFFFF' | If non-zero, the fraction of a second. 'f' returns tenths of a second, 'fff' returns milliseconds and 'fffffff' returns 10 millionths of a second |
2011-06-17 14:35:20.718 (f) -> 7 2011-06-17 14:35:20.050 (f) -> (no output) |
| 'g' or 'gg' | The period or era. | 2011-06-17 14:35:20 -> A.D. |
| 'h' | The hour, using a 12-hour clock from 1 to 12. | 2011-06-17 03:35:20 -> 3 2011-06-17 14:35:20 -> 2 |
| 'hh' | The hour, using a 12-hour clock from 01 to 12. | 2011-06-17 03:35:20 -> 03 2011-06-17 14:35:20 -> 02 |
| 'H' | The hour, using a 24-hour clock from 0 to 23. | 2011-06-17 03:35:20 -> 3 2011-06-17 14:35:20 -> 14 |
| 'HH' | The hour, using a 24-hour clock from 00 to 23. | 2011-06-17 03:35:20 -> 03 2011-06-17 14:35:20 -> 14 |
| 'K' | Time zone information. | 2011-06-17 14:35:20 (utc) -> Z 2011-06-17 14:35:20 (local time, +2 hours) -> +02:00 |
| 'm' | The minute, from 0 through 59. | 2011-06-17 14:35:20 -> 35 2011-06-17 14:07:20 -> 7 |
| 'mm' | The minute, from 00 through 59. | 2011-06-17 14:35:20 -> 35 2011-06-17 14:07:20 -> 07 |
| 'M' | The month, from 1 through 12. | 2011-06-17 14:35:20 -> 6 |
| 'MM' | The month, from 01 through 12. | 2011-06-17 14:35:20 -> 06 |
| 'MMM' | The abbreviated name of the month. | 2011-06-17 14:35:20 -> Jun |
| 'MMMM' | The full name of the month. | 2011-06-17 14:35:20 -> June |
| 's' | The second, from 0 through 59. | 2011-06-17 14:35:20 -> 20 2011-06-17 14:35:07 -> 7 |
| 'ss' | The second, from 00 through 59. | 2011-06-17 14:35:20 -> 20 2011-06-17 14:35:07 -> 07 |
| 't' | The first character of the AM/PM designator. | 2011-06-17 14:35:20 -> P |
| 'tt' | The AM/PM designator. | 2011-06-17 14:35:20 -> PM |
| 'y' | The year, from 0 to 99. | 2003-06-17 14:35:20 -> 3 2011-06-07 14:35:20 -> 11 |
| 'yy' | The year, from 00 to 99. | 2003-06-17 14:35:20 -> 03 2011-06-07 14:35:20 -> 11 |
| 'yyy' | The year, with a minimum of three digits. | 2011-06-17 14:35:20 -> 2011 0901-06-07 14:35:20 -> 901 |
| 'yyyy' | The year as a four-digit number. | 2011-06-17 14:35:20 -> 2011 0901-06-07 14:35:20 -> 0901 |
| 'yyyyyy' | The year as a five-digit number. | 2011-06-17 14:35:20 -> 02011 |
| 'z' | Hours offset from UTC, with no leading zeros. | 2011-06-17 14:35:20 (utc) -> 0 2011-06-17 14:35:20 (local time, +2 hours) -> 2 |
| 'zz' | Hours offset from UTC, with a leading zero for a single-digit value. | 2011-06-17 14:35:20 (utc) -> 00 2011-06-17 14:35:20 (local time, +2 hours) -> 02 |
| 'zzz' | Hours and minutes offset from UTC. | 2011-06-17 14:35:20 (utc) -> +00:00 2011-06-17 14:35:20 (local time, +2 hours) -> +02:00 |
| ':' | The time separator. | 2011-06-17 14:35:20 -> : |
| '/' | The date separator. | 2011-06-17 14:35:20 -> / |
| '%' | Defines the following character as a custom format specifier. | 2011-06-17 14:35:20 (%h)-> 2 |
| \ | Escape character which causes the next character to be interpreted as a literal rather than as a custom format specifier. | 2011-06-17 14:35:20 (h \h) -> 2 h |
| 'text' or "text" | Literal text delimiter which indicates that the enclosed characters should be copied to the result unchanged. | 2011-06-17 14:35:20 ('abc:' hh:mm t) -> abc: 14:35 P |
| Other | All other characters are copied to the result string unchanged. | 2011-06-17 14:35:20 (abc hh:mm t) -> abc 14:35 P |
Examples
{% Var date = #2011-06-17 14:35:20# %}
Answers: {{ date.Day }},
{{ date.Hour }},
{{ date.ToText('hh:mm:ss') }}.
The above example would output: Answers: 17, 14, 02:35:20 (for the 'en-GB' culture).