Date and time format
Use date and time functions to convert and transform date and time data. For example, you can change the date format, convert time based on time zones, convert text into date or time data, and more. Below is a list of supported date and time functions in AhaChat along with descriptions and details for each function.
How to Use
Create a Attribute block in the AhaChat flow to store the attribute with the value as date and time parameters to format.
Example: {{formatDate(date, MM-DD-YYYY)}}
→ where date
is the attribute containing the customer's date/time.
{{formatDate(date, format, [timezone])}}
When to use: You have a Date value that you want to convert (format) into a Text value (human-readable representation) like 12-10-2015 20:30 or August 18, 2025, 10:00 AM.
Parameters
date: The Date value to be converted.
format: The specified format for the date/time. Example: DD.MM.YYYY HH:mm
timezone: (Optional) The time zone used for conversion, see the list here.
Note
Only values listed in the "TZ identifier" column are recognized as valid time zones.
Return Value and Type
A text representation of the given Date value according to the specified format and time zone. The type is Text.
Examples
The examples below use the input time zone: Asia/Ho_Chi_Minh
{{formatDate(2025-10-01, MM/DD/YYYY)}}
= 10/01/2015{{formatDate(01/10/2025 09:30:00, YYYY-MM-DD HH:mm A)}}
= 2015-10-01 09:30 AM{{formatDate(01/10/2025 21:30:00, YYYY-MM-DD HH:mm A)}}
= 2015-10-01 21:32 PM{{formatDate(2025-10-01 07:00:00, DD.MM.YYYY HH:mm, America/Chicago)}}
= 30.09.2025 18:00
{{addSeconds(date, number)}}
Returns a new date that is the result of adding a certain number of seconds to a date.
{{addSeconds(08-12-2025 15:55:20, 2)}}
= 08-12-2025 15:55:22
{{addMinutes(date, number)}}
Returns a new date that is the result of adding a certain number of minutes to a date.
{{addMinutes(08-12-2025 15:55:20, 2)}}
= 08-12-2025 15:57:20
{{addHours(date, number)}}
Returns a new date that is the result of adding a certain number of hours to a date.
{{addHours(08-12-2025 15:55:20, 2)}}
= 08-12-2025 17:55:20
{{addDays(date, number)}}
Returns a new date that is the result of adding a certain number of days to a date.
{{addDays(08-12-2025 15:55:20, 2)}}
= 10-12-2025 15:55:20
{{addMonths(date, number)}}
Returns a new date that is the result of adding a certain number of months to a date.
{{addMonths(08-12-2025 15:55:20, 2)}}
= 08-02-2025 15:55:20
{{addYears(date, years)}}
Returns a new date that is the result of adding a certain number of years to a date.
{{addYears(08-12-2025 15:55:20, 2)}}
= 08-12-2027 15:55:20
{{subSeconds(date, number)}}
Returns a new date that is the result of subtracting a certain number of seconds from a date.
{{subSeconds(08-12-2025 15:55:20, 2)}}
= 08-12-2025 15:55:18
{{subMinutes(date, number)}}
Returns a new date that is the result of subtracting a certain number of minutes from a date.
{{subMinutes(08-12-2025 15:55:20, 2)}}
= 08-12-2025 15:53:20
{{subHours(date, number)}}
Returns a new date that is the result of subtracting a certain number of hours from a date.
{{subHours(08-12-2025 15:55:20, 2)}}
= 08-12-2025 13:55:20
{{subDays(date, number)}}
Returns a new date that is the result of subtracting a certain number of days from a date.
{{subDays(08-12-2025 15:55:20, 2)}}
= 06-12-2025 15:55:20
{{subMonths(date, number)}}
Returns a new date that is the result of subtracting a certain number of months from a date.
{{subMonths(08-12-2025 15:55:20, 2)}}
= 08-10-2025 15:55:20
{{subYears(date, years)}}
Returns a new date that is the result of subtracting a certain number of years from a date.
{{subYears(08-12-2025 15:55:20, 2)}}
= 08-12-2023 15:55:20
{{setSecond(date, number)}}
Returns a new date with the second specified in the parameter. Accepts numbers from 0 to 59. If a number outside this range is given, it returns a date with seconds from the previous or next minute.
{{setSecond(08-12-2025 11:36:39, 10)}}
= 08-12-2025 11:36:10{{setSecond(08-12-2025 11:36:39, 61)}}
= 08-12-2025 11:37:01
{{setMinute(date, number)}}
Returns a new date with the minute specified in the parameter. Accepts numbers from 0 to 59. If a number outside this range is given, it returns a date with minutes from the previous or next hour.
{{setMinute(08-12-2025 11:36:39, 10)}}
= 08-12-2025 11:10:39{{setMinute(08-12-2025 11:36:39, 61)}}
= 08-12-2025 12:01:39
{{setHour(date, number)}}
Returns a new date with the hour specified in the parameter. Accepts numbers from 0 to 59. If a number outside this range is given, it returns a date with hours from the previous or next day.
{{setHour(08-12-2025 11:36:39, 10)}}
= 08-12-2025 10:36:39{{setHour(08-12-2025 11:36:39, 10)}}
= 09-12-2025 01:36:39
{{setDay(date, number/name of the day in English)}}
Returns a new date with the day specified in the parameter. Can be used to set the day of the week, with Sunday as 1 and Saturday as 7. If the value given is from 1 to 7, the result date will fall within the current week (Sunday to Saturday). If a number outside this range is given, it returns a date from the previous or next week.
{{setDay(08-12-2025 11:36:39, tuesday)}}
= 09-12-2025 11:36:39{{setDay(08-12-2025 11:36:39, 1)}}
= 07-12-2025 11:36:39{{setDay(08-12-2025 11:36:39, 7)}}
= 13-12-2025 11:36:39
{{setDate(date, number)}}
Returns a new date with the day of the month specified in the parameter. Accepts numbers from 1 to 31. If a number outside this range is given, it returns a date from the previous or next month.
{{setDate(08-12-2025 11:36:39, 5)}}
= 05-12-2025 11:36:39{{setDate(08-12-2025 11:36:39, 32)}}
= 01-01-2026 11:36:39
{{setMonth(date, number/name of the month in English)}}
Returns a new date with the month specified in the parameter. Accepts numbers from 1 to 12. If a number outside this range is given, it returns a month from the previous or next year.
{{setMonth(08-12-2025 11:36:39, 5)}}
= 08-05-2025 11:36:39{{setMonth(08-12-2025 11:36:39, 17)}}
= 08-05-2026 11:36:39{{setMonth(08-12-2025 11:36:39, january)}}
= 08-01-2025 11:36:39
{{setYear(date, year)}}
Returns a new date with the year specified in the parameter. Accepts a number greater than 0.
{{setYear(08-12-2025 11:36:39, 2030)}}
= 08-12-2030 11:36:39
Example Templates
How to Calculate the nth Day of the Week in a Month
If you need to calculate a date corresponding to the nth occurrence of a specific weekday in a month (e.g., the first Tuesday, the third Friday, etc.), you can use the following formula:
You can use the following formula:
{{setDay(date, weekday, week number)}}
{{setDay(08-12-2025 11:36:39, Monday, 3)}}
= 15-12-2025 11:36:39
{{setDay(08-12-2025 11:36:39, Tuesday)}}
= 09-12-2025 11:36:39
date: A specific date. To calculate the nth weekday of the current month, use the NOW()
variable.
{{setDay(NOW(), Tuesday)}}
How to Calculate the Number of Days Between Two Dates
Use the following formula:
{{calculateDay(date1, date2)}}
Example: If date1 is January 1, 2025, and date2 is January 10, 2025, this formula will return 9 (the number of days between the two dates).
{{calculateDay(01-01-2025, 10-01-2025)}}
= 9
How to Convert Seconds to Hours, Minutes, and Seconds
Use the following formula:
{{convertSeconds(seconds, format)}}
Example: If you have 3661 seconds, this formula will return 1:1:1 (1 hour, 1 minute, 1 second).
{{convertSeconds(3661, HH:mm:ss)}}
= 01:01:01
{{convertSeconds(7200)}}
= 02:00:00
Note
The value of seconds
must be a number. This function is only suitable if the seconds
value is less than 86,400 (less than one day).
Hope this information will be helpful for you in working with date and time functions. If you have any additional questions, feel free to let me know.