How to Format Date and Time in Chatbot Builder AI

Modified on Sun, 12 Jan at 12:04 AM

Step-by-Step Guide to Formatting Dates in Your Chatbot


Imagine your chatbot greeting users with a warm, localized “Good morning!” or reminding them of their last interaction. Clear and accurate time displays help personalize messages, set reminders, and keep conversations relevant.


In Chatbot Builder AI, time data is often stored as a Unix timestamp (e.g., 1735665749), which isn’t user-friendly. But don’t worry! This guide will help you convert those timestamps into readable formats like December 31, 2024, 12:22 PM, so your bot can shine.


Benefits of Formatting Date and Time

    •    Clarity: Friendly formats like “December 31, 2024” are easier to understand than raw timestamps.

    •    Consistency: Match your audience’s preferred format, whether that’s MM/DD/YYYY or DD/MM/YYYY.

    •    Personalization: Display user-specific times, like their local time or the date of their last interaction, to create a more engaging experience.


Common System Fields for Date and Time

    •    {{current_time}}: The bot’s current time (usually stored as a Unix timestamp).

    •    {{last_interaction}}: The timestamp of the user’s last interaction.

    •    {{current_user_time}}: The user’s local time, when available.


Tip: You can store formatted versions of these fields in custom user fields for better organization.


How to Format Dates With AI Actions in Your Chatbot


Formatting dates helps your chatbot turn user input like “next Monday at 9 am” into a clear and consistent format, such as MM/DD/YYYY HH:MM. Follow these steps to set it up:


Steps to Format a Date

  1. Collect User Input:
    Make sure your chatbot asks for a date and time, like "When do you want the appointment?"

  2. Use AI to Understand the Input:
    Set up an AI Action to process what the user says. It should consider the current system time ({{current_user_time}}) to interpret phrases like “tomorrow” or “next Friday.”

  3. Format the Output:
    The AI Action should convert the input into a standard format (e.g., 01/17/2025 14:00) and send it back for display or further use.

Why Examples Are Important

Always test your AI with real examples of user inputs like:

  • “I need the appointment tomorrow at 10 am.”
  • “Next Monday at 2 pm works for me.”

And make sure the responses are clear and accurate, like:

  • 01/11/2025 10:00
  • 01/15/2025 14:00

Using examples ensures the chatbot understands users and formats dates correctly every time.


Examples use in the Screenshot Above:


User: I wnat an appintment for tomorrow at 10 am.

Assistant: 01/11/2025 10:00


User: I want the appointment Friday at 3pm.

Assistant: 01/12/2025 15:00


User: I need an appointment next Monday at 9am.

Assistant: 01/15/2025 09:00


User: Can you book me for next Wednesday at 2pm?

Assistant: 01/17/2025 14:00


User: Schedule me for today at 4pm.

Assistant: 01/10/2025 16:00


User: Let’s do the appointment Saturday morning at 8am.

Assistant: 01/13/2025 08:00


Pro Tip:

Always use the current time ({{current_user_time}}) to avoid mistakes with relative dates like “next week.”


How to Format Dates Without AI in Your Chatbot


1. Choose Your Flow


Decide where in your bot’s flow you want to display or use date/time information.


2. Add a “Format Date” Action

    •    Insert a new Action step.

    •    Select Format Date/Date & Time to convert a Unix timestamp into a readable format.


3. Select the Field to Format

    •    Common fields to format include {{current_time}}, {{last_interaction}}, or {{current_user_time}}.


4. Set Your Date/Time Format


Use a format pattern to customize the output. For example:


Pattern: l, F jS, Y, g:i a

Output: Tuesday, December 31st, 2024, 12:22 pm


Pattern Breakdown:

    •    l: Full day name (e.g., Tuesday)

    •    F: Full month name (e.g., December)

    •    jS: Day of the month with ordinal suffix (e.g., 31st)

    •    Y: Year in four digits

    •    g:i a: 12-hour clock with minutes and am/pm


5. Choose a Time Zone (Optional)

    •    Page Time Zone: The default set in your bot’s settings.

    •    User Time Zone: Automatically adjusts to the user’s local time.

    •    Custom: Specify a specific time zone, like UTC.


6. Save the Formatted Output


Store the result in a new custom field (e.g., {{formatted_time}}) or overwrite an existing one. You can now use this formatted field in your messages.


Format Patterns and Use Cases:


Category

Character

Description

Example

Day

d

Day of the month, 2 digits

01 to 31

Day

j

Day of the month, no leading zero

1 to 31

Day

l

Full textual day (Sunday-Saturday)

Tuesday

Day

D

Three-letter day (Mon, Tue, Wed…)

Tue

Day

S

Ordinal suffix (st, nd, rd, th)

31st

Month

F

Full month (January-December)

December

Month

m

Numeric month, with leading zeros

12

Month

n

Numeric month, no leading zeros

12

Month

M

Three-letter month (Jan, Feb…)

Dec

Year

Y

Full year (4 digits)

2024

Year

y

Short year (2 digits)

24

Time

a

Lowercase am/pm

pm

Time

A

Uppercase AM/PM

PM

Time

g

12-hour format, no leading zero

12

Time

h

12-hour format, leading zero

9

Time

G

24-hour format, no leading zero

0 to 23

Time

H

24-hour format, leading zero

00 to 23

Time

i

Minutes, leading zero

00 to 59

Time

s

Seconds, leading zero

00 to 59


Using Formatted Fields in Messages


Before Formatting:


    “Current time is {{current_time}}. Last interaction was {{last_interaction}}.”


Example Output:


    “Current time is 1735665749. Last interaction was 2024-12-31 12:21.”


After Formatting:

Format {{current_time}} into {{formatted_time}} with the pattern l, F jS, Y, g:i a.


Updated Message:


    “The time is now {{formatted_time}}.”


Example Output:


    “The time is now Tuesday, December 31st, 2024, 12:22 pm.”


Extra Tips

    •    Track Last Interactions:

Format {{last_interaction}} to politely remind users of their last visit.

    •    Personalize with Local Time:

Use {{current_user_time}} to tailor messages to the user’s time zone. For example:

    “Good evening! It’s {{current_user_time}} in your time zone.”

    •    Calculate Time Differences:

If storing timestamps in Unix format, you can calculate elapsed time like this:

    ({{end_time}} - {{start_time}}) / 60 (minutes).


Example Flow:




1. Action: Format Date

    •    Input: {{current_time}}

    •    Format: l, F jS, Y, g:i a

    •    Output: {{formatted_time}}


2. Send Message:


    “Current time (unformatted): {{current_time}}

Current time (formatted): {{formatted_time}}.”


User Sees:


    Current time (unformatted): 1735665749

Current time (formatted): Tuesday, December 31st, 2024, 12:22 pm


Conclusion


Remember, by formatting date and time in Chatbot Builder AI, you can transform raw timestamps into clear and engaging displays. Rather than relying on raw timestamps, utilizing the built-in system field CUFs ensures consistent, professional time formatting across your entire chatbot experience. 

With these formatting techniques in hand, you're ready to create agents and assistants that communicate time in a way that feels natural and intuitive to your users.




Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article