
The Function Block DT2STR converts a time with the specified format into a string.
The input defines the date in DT#, which is used for calculation. If no date is specified, then it is calculated with the timestamp 0.
The input defines the format as a string. If no value is set or left empty, then the string "Y-m-d H:i:s" is assumed.
Tip: To output a letter or d, each letter must be marked with the escape characters \. For example: "\d\a\y: d" outputs "day: 01".
| Format Character | Description | Example Return Values |
|---|---|---|
| Day | ||
| d | Day of the month, 2 digits with leading zero | 01 to 31 |
| D | Day of the week, abbreviated to three letters | Mon to Sun |
| j | Day of the month without leading zeros | 1 to 31 |
| l (small 'L') | Full textual representation of the day of the week | Sunday to Saturday |
| N | ISO-8601 numeric representation of the day of the week | 1 (for Monday) to 7 (for Sunday) |
| S | English ordinal suffix for the day of the month, 2 characters | st, nd, rd or th. Recommended for use with j. |
| w | Numeric representation of the day of the week | 0 (for Sunday) to 6 (for Saturday) |
| z | The day of the year (starting from 0) | 0 to 365 |
| Week | ||
| W | ISO-8601 week number of the year, with weeks starting on Monday | Example: 42 (the 42nd week in the year) |
| Month | ||
| F | Full textual representation of a month, such as January or March | January to December |
| m | Month as a number with leading zeros | 01 to 12 |
| M | Three-letter abbreviation of the month name | Jan to Dec |
| n | Month as a number without leading zeros | 1 to 12 |
| t | Number of days in the specified month | 28 to 31 |
| Year | ||
| L | Whether it's a leap year or not | 1 for a leap year, otherwise 0 |
| o | ISO-8601 calendar year number. This gives the same value as Y, except when the ISO week number (W) belongs to a different year, in which case that year is used. | Examples: 1999 or 2003 |
| Y | Four-digit year representation | Examples: 1999 or 2003 |
| y | Two-digit representation of a year | Examples: 99 or 03 |
| Time | ||
| a | Lowercase Ante meridiem and Post meridiem (am or pm) | am or pm |
| A | Uppercase Ante meridiem and Post meridiem (AM or PM) | AM or PM |
| B | Swatch Internet Time | 000 to 999 |
| g | 12-hour format of an hour without leading zeros | 1 to 12 |
| G | 24-hour format of an hour without leading zeros | 0 to 23 |
| h | 12-hour format of an hour with leading zeros | 01 to 12 |
| H | 24-hour format of an hour with leading zeros | 00 to 23 |
| i | Minutes with leading zeros | 00 to 59 |
| s | Seconds with leading zeros | 00 to 59 |
| u | Microseconds. Always outputs 000000. | Example: 000000 |
| Timezone | ||
| e | Timezone identifier | Examples: UTC, GMT, Atlantic/Azores |
| I (capital 'i') | Whether the date falls into daylight saving time | 1 if in daylight time, otherwise 0. |
| O | Difference to Greenwich Mean Time (GMT) in hours | Example: +0200 |
| P | Difference to Greenwich Mean Time (GMT) in hours with a colon between hours and minutes | Example: +02:00 |
| T | Abbreviation of the timezone | Examples: EST, MDT... |
| Z | Timezone offset in seconds. The offset for timezones west of UTC is always negative and for timezones east of UTC always positive. | -43200 to 50400 |
| z | Returns the day of the year without leading zero | |
| Full Date/Time | ||
| c | ISO 8601 date | 2004-02-12T15:19:21+00:00 |
| r | Date formatted according to » RFC 2822 | Example: Thu, 21 Dec 2000 16:01:07 +0200 |
| U | Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) | See also Function Block TIME |
The output returns a string with the specified format.