Skip to main content

Format dates using the Answer Utility block

Overview

The Format Date action lets your bot convert a date from one format to another. It's particularly useful for converting computer friendly date strings to a human readable form.

Here are a few Format Date use cases:

  • Converting a date from one standard format to another.

    Example: "2021-05-18" to "May 18, 2021"

  • Converting a date timestamp.

    Example: "2021-05-18T05:00:00.000+0000" to "May 18, 2021"

  • Converting to a localized format.

    Example: "May 18, 2021" to "le 18 mai 2021"

  • Converting a Unix epoch date.

    Example: "1621296000" to "2021-05-18"

Configure the Format Date Block

  1. Click the Select Action drop-down, then select Format Date. This reveals the options for configuring the Format Date action.

    format_date_basic.png
  2. Complete the following mandatory fields in the Select Variables for Inputs section:

    Date

    Add the date variable you wish to format.

    Output Format

    Define the format of the outputted date by adding one of the following to the Output Format field:

    • ISO - Add "iso" to use the ISO-8601 formatting standard.

    • Epoch - Add "epoch" to use the epoch-unix formatting standard in seconds.

    • Custom - Use Python notation to create custom date formatting. See also non-English notation.

  3. Click the Select Optional Inputs drop-down menu to add your choice of optional fields, as required:

    Input Format (optional)

    Define the format of the inputted date.

    Locale (optional)

    Define the date format for a non-English language or locale.

  4. Click the Select Optional Variables drop-down and select Formatted Date. This adds the Choose a Variable drop-down menu for the formatted date result.

  5. Click the Choose a Variable drop-down menu, then select an existing variable or create a new variable to capture the formatted date.

  6. Click the Fallback Answer drop-down menu and select an Answer to display if an error occurs during the block’s operation.

  7. Click Save.

The Formatted Date variable can be inserted in any bot dialogue or process where this specific format is required.

Formatting Code Examples

The Format Date block uses Python datetime formatting. But don't worry! The code for each format parameter is simply a combination of two characters: a percentage symbol followed by a single letter. Keep in mind that letter casing is important for datetime formatting.

Format <YYYY-MM-DD> as <Month Day, Year>

Example: "2021-05-18" to "May 18, 2021"

format_date_a.png

Format <Month Day, Year> as <ISO 8601 date-timestamp>

Example: "05-18-2021" to "2021-05-18T00:00:00"

format_date_b.png

Have any questions? Contact your Ada team—or email us at help@ada.support.