Skip to main content

Format dates using the Answer Utilities 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.

  1. 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 - There are two ways to define custom date formats, depending on the locale you're using:

      • If you're using en as your locale, use Python notation. This notation is only compatible with the en locale.

      • If you're using any locale other than en, use non-English notation.

  2. 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.

    This field can contain any two-letter ISO 639-1 code, which you can find on the Codes for the Representation of Names of Languages page on the Library of Congress website.

  3. 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.

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

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

  6. 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.

Convert YYYY-MM-DD to Month Day, Year

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

Convert Month Day, Year to ISO 8601 date-timestamp

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


Have any questions? Contact your Ada team—or email us at .