Skip to main content
Calculating the time difference between two dates is a common requirement for reservation bots (nights stayed), age verification, or event countdowns. This guide uses Unix Timestamps (total seconds since January 1, 1970) to perform accurate date arithmetic.

Prerequisites

Before you begin, ensure you have:
  • Basic knowledge of the Flow Builder.
  • Understanding of Custom Fields and Variables.

Step-by-Step Guide

1

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}}
Ensure you capture these dates using a Date Input type to guarantee they are in a valid format before proceeding.
2

Convert Dates to Seconds

To perform math, you must convert the readable dates into a numerical format (Unix Timestamp).
  1. Add a new Action block in your flow.
  2. Navigate to Tools > Format Date.
  3. 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}}.
  4. Repeat this for the Check-Out date to create {{check_out_seconds}}.
3

Calculate the Difference

Subtract the start time from the end time to get the duration in seconds.
  1. Add a Set Custom Field action.
  2. Set the Operation to Set to (or Calculate Formula).
  3. Enter the subtraction formula:
{{check_out_seconds}} - {{check_in_seconds}}
  1. Save the result to a variable named {{difference_in_seconds}}.
4

Convert Seconds to Days

Convert the raw seconds back into a human-readable number (Days).
  1. Add another Set Custom Field action.
  2. Divide your seconds result by the number of seconds in a day (86400).
{{difference_in_seconds}} / 86400
  1. 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.
5

Display the Result

Use the final variable to display the result to your user.Your stay is for {{difference_in_days}} nights.

Advanced Usage

Calculating Age

To determine a user’s age, compare their birth date against the current time.
  1. Date 1: User’s {{birth_date}}.
  2. Date 2: Current Date (Use the now variable or system time).
  3. Calculate the difference in seconds.
  4. Divide by 31,536,000 (approximate seconds in a year).

Countdown Timers

For future events:
  1. Date 1: Current Date.
  2. Date 2: Event Date.
  3. Subtract Current Date from Event Date.
  4. Convert the remaining seconds into Days, Hours, or Minutes as needed.

Frequently Asked Questions

Yes. divide the {{difference_in_seconds}} by:
  • Weeks: 604,800
  • Months: 2,628,000 (Approximate average)
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.