Formatting dates and times in scripts allows the bot to save customer responses and display them in an understandable format. For example, a customer writes in a dialogue: “tomorrow at noon.” The bot recognizes the response, saves it in a variable, and displays it in the format: “Thursday, July 17, 2:00 p.m.”
Variables for storing dates and times are declared in advance in the start block Settings — on the Variables and Templates tab. Then, the script blocks receive the value from the customer and write it to the declared variables. After that, the variable value can be displayed in dialogs.
If the display format is not specified, the date and time are shown by default:
To change the display format, use the template: {variable_name|format:format_code}. The list of available formats is shown in the table below.
Translated with DeepL.com (free version)
As an example, the following date and time is used below, “October 3, 2022, 8:15”.
| Formatting code | Description / designation | Example of use | Result |
|---|---|---|---|
| a | «am» or «pm» | {variable name|format:а} |
ам |
| A | «AM» or «PM» | {variable name|format:A} |
АМ |
| d | Day of the month (01-31) | {variable name|format:d} |
03 |
| D | Abbreviated name of the day of the week (first three letters) | {variable name|format:D} |
Mon |
| F | Full name of the month | {variable name|format:F} |
October |
| g | Clock (12-hour format without leading zeros) | {variable name|format:g} |
8 |
| G | Clock (24-hour format without leading zeros) | {variable name\\|format:G} |
8 |
| h | Clock (12-hour format) | {variable name|format:h} |
08 |
| H | Clock (24-hour format) | {variable name|format:H} |
08 |
| i | Minutes (00-59) | {variable name\\|format:i} |
15 |
| j | Day of the month without leading zeros (1-31) | {variable name|format:j} |
3 |
| l | Full name of the day of the week | {variable name|format:l} |
Monday |
| L | Leap year sign (0 - normal year or 1 - leap year) | {variable name|format:L} |
0 |
| m | Month number (01-12) | {variable name|format:m} |
10 |
| M | Abbreviated name of the month (three letters) | {variable name|format:M} |
Oct |
| n | Month (1-12) | {variable name|format:n} |
10 |
| s | Seconds (00-59) | {variable name|format:s} |
00 |
| t | Number of days in a given month (28-31) | {variable name|format:t} |
31 |
| w | Number of the day of the week (0 - Sunday, 6 - Saturday) | {variable name|format:w} |
1 |
| y | Year (last two digits) | {variable name|format:y} |
22 |
| Y | Year (four digits) | {variable name|format:Y} |
2022 |
| z | Day number of the year (0-365) | {variable name|format:z} |
275 |
You can use several formatting codes from the list above at the same time. You can use different characters as separators: period, comma, semicolon, colon, plus, minus, etc., or no separator at all. You can also use various words and phrases in the format string.
For example:
| Formatting string | Result |
|---|---|
{variable name|format:l d.m.y} |
Monday 03.10.22 |
{variable name|format: current day: l, current date: d.m.y} |
Current day: Monday, current date: 03.10.22 |
{variable name|format:h:i:s} |
08:15:00 |
{variable name|format:g hours i minutes s seconds} |
8 hours 15 minutes and 00 seconds |