Prerequisites
Before you begin, ensure you have:
- Basic knowledge of the Flow Builder.
- Understanding of Custom Fields and Variables.
Step-by-Step Guide
Collect the Dates
Obtain the two dates you wish to compare and store them in Custom Fields.
- Start Date:
{{check_in_date}}(e.g., user input or system date) - End Date:
{{check_out_date}}
Convert Dates to Seconds
To perform math, you must convert the readable dates into a numerical format (Unix Timestamp).
- Add a new Action block in your flow.
- Navigate to Tools > Format Date.
- Configure the Check-In date:
- Date & Time: Select
{{check_in_date}}. - Format: Enter
"U"(Unix Timestamp format). - Save to: Create a new number field
{{check_in_seconds}}.
- Date & Time: Select
- Repeat this for the Check-Out date to create
{{check_out_seconds}}.
Calculate the Difference
Subtract the start time from the end time to get the duration in seconds.
- Add a Set Custom Field action.
- Set the Operation to
Set to(or Calculate Formula). - Enter the subtraction formula:
- Save the result to a variable named
{{difference_in_seconds}}.
Convert Seconds to Days
Convert the raw seconds back into a human-readable number (Days).
- Add another Set Custom Field action.
- Divide your seconds result by the number of seconds in a day (
86400).
- Save this to
{{difference_in_days}}.
Why 86,400?There are 60 seconds in a minute, 60 minutes in an hour, and 24 hours in a day.
60 * 60 * 24 = 86,400 seconds.Advanced Usage
Calculating Age
To determine a user’s age, compare their birth date against the current time.- Date 1: User’s
{{birth_date}}. - Date 2: Current Date (Use the
nowvariable or system time). - Calculate the difference in seconds.
- Divide by 31,536,000 (approximate seconds in a year).
Countdown Timers
For future events:- Date 1: Current Date.
- Date 2: Event Date.
- Subtract Current Date from Event Date.
- Convert the remaining seconds into Days, Hours, or Minutes as needed.
Frequently Asked Questions
Can I calculate weeks or months?
Can I calculate weeks or months?
Yes. divide the
{{difference_in_seconds}} by:- Weeks:
604,800 - Months:
2,628,000(Approximate average)
What if the date format is different?
What if the date format is different?
Chatbot Builder AI’s Format Date tool handles most standard date formats automatically. Ensure your input collection step validates that the user actually entered a date.
