• Home

  • Automation with Zapier

  • Zapier tutorials

Zapier tutorials

5 min read

How to compare and calculate two dates in a Zap

By Krystina Martinez · March 21, 2023
zapier-formatter-guide primary img

Dates can be deceptively tricky for humans and computers. Though computers are arguably better at comparing and calculating dates, they can only do so if the date formats match. (I wish I had that excuse.)

Date formats aren't an issue if you're working within the same app, but what if you're trying to automate date-related information across your work tools? Luckily, Zapier has a built-in tool called Formatter that can automatically compare and calculate dates across your favorite apps.

This tutorial will show you how to use Formatter's Date Compare function in a Zap—what we call Zapier's automated workflows—so you can accurately forecast deadlines, your workload, and other planning for your business. 

This workflow requires you to use Formatter, a built-in Zapier tool available to users on a paid plan or during a trial period.

Table of contents

  • What is Compare Dates in a formatter step?

  • Before you begin

  • How to compare dates with a formatter step

  • Use the results elsewhere

What is Compare Dates in Formatter?

Formatter is Zapier's built-in utility tool for Zaps. It lets you transform app information into the format you need for later Zap steps, such as manipulating text or adjusting date formats.

Formatter has several date functions, one of which is Compare Dates. You can tell Zapier the two dates you want to compare, and Formatter will let you know if those dates fall on the same day, as well as the duration between those dates.

When you might use Compare Dates: 

  • You want to calculate the time between two dates. Some apps may do this for you already, but what if you want to perform your own calculations? For example, you could compare the time a lead spent between deal stages to understand how long it takes to close a sale, then use that to calculate your team's capacity to hit certain sales goals. 

  • You want to reduce how often a Zap runs based on app changes. Some spreadsheet and database apps can start a Zap too often because they might use timestamp fields to judge whether a record is new or updated. You can compare those timestamps and use a filter or path stepavailable on paid Zapier plans—to determine the next steps. We'll cover how to do that later on

  • You want to check if certain data matches up between apps. Not sure if the date from your project management tool matches up with your personal to-do? You can compare the dates, then tell your Zap what to do if something doesn't match up. 

Before you begin

For this tutorial, we'll assume you're familiar with how Zapier works. If not, don't worry: It's free to sign up for a Zapier account. We also have a guide to creating your first Zap

Then, make sure you're in the Zap editor, where you can create and edit Zaps. You can either use an existing Zap you've created or build a new one from scratch. Just make sure your new Zap is created up to the point where you want to compare two dates—the dates don't have to come from the same app, either.

For this example, I'm setting up a Zap to flag any last-minute tasks in Asana. I'll use Formatter to compare the start and the end dates and determine how much time I have for a task.

You can still follow along if you want to compare dates from a different app. Our formatter step will come right after our trigger—the event that starts a Zap. 

Note: You can add a formatter step right after a trigger or an action—the event your Zap performs once it's triggered. 

How to compare and subtract two dates

Click the plus sign to add a step to your Zap. Then, search for and select Formatter by Zapier as the app, Date / Time as the event, and click Continue

Select the Formatter tool and the event it will perform.

Click on the dropdown beneath Transform and select Compare Dates

Select the Compare Date transformation from the dropdown menu.

The editor will prompt you to provide start and end dates. Your start date doesn't have to be an "official" start date, as labeled in your app. You can also think of your start date as the main comparison point. 

To compare dates, map a dynamic value from a previous Zap step. Dynamic values are field values that change each time a Zap runs, depending on the information a Zap step receives, such as the due date for a new task. 

Click on the Start Date field to see a dropdown menu of data from previous Zap steps. Search for and select the dynamic value you want to use.

Note: If you type in a static date, Zapier will interpret that you want to use the same date every time your Zap runs. 

Click on a field in the Zap editor and select a date from the dropdown menu.

Then, select the dynamic value you want to use as your end date. 

Select a dynamic value to use in the End Date Value field.

If you want to use the date your Zap triggered, type in the command {{zap_meta_human_now}}. The Zap editor will show an empty value, but once your Zap is on, it will use the time your Zap triggered. Learn more about using the current time in a Zap

Don't worry if your comparison dates are in different formats. Zapier will do its best to interpret the correct date. However, if you'd like, you can also tell Zapier the format for your start and end dates.  

Select the date format to convert the start and end dates.

Don't see your date format listed? You can provide a custom value with the correct format. Check out this handy table for creating your own custom date value.

Once you're done, click Continue, and then Test action. You'll see a success message with Formatter's results, which will include the following: 

  • The duration between the two dates, down to the second if your dates also included times.

  • Dates swapped: If your end date came before your start date, Zapier lets you know that the dates were swapped to calculate the time difference.

  • Same dates: Zapier will provide a true or false result if the dates are the same. If the dates are the same but the time is different, Zapier will still consider it the same date.

Check the Formatter results carefully to make sure the dates were interpreted correctly. 

Test the Formatter step and review the results.

If something is off, return to the previous step, make adjustments, and keep testing until you get the correct result. 

Use your results in your Zap

Now you can use the comparison results elsewhere in your Zap. Click the plus button to add another step to your Zap. 

Add another step to the Zap.

Then, set up your action using your Formatter results. For example, you could pass on the difference between the two dates to another app. 

You can combine text and dynamic values from previous steps in Zap editor fields.

Create conditional Zaps

You can also use your Formatter results with other built-in Zapier tools to create more complex workflows.  

Use a filter or a path step

Don't want your Zap to run if your start and end dates are the same? Select the fields from the Formatter step you want to use in a filter or path, then select the condition you want to evaluate. 

Select a Formatter field to filter.

In the example below, I set up rules for a path if assigned an Asana task with a quick deadline. The path rules will only let this Zap continue if the start and due dates are the same or I have less than five days to complete the task. 

Use filter and path rules to evaluate Formatter's output.

Use (Boolean) conditions for the Same Dates and Swapped Dates fields and (Number) conditions for the time difference. This will ensure your filter or path rules evaluate those fields correctly.

Learn more about filtering rules you can use in Zaps

Perform a math operation

You can also use your date comparison results in a spreadsheet-style formula or math operation. Add another Formatter step, select the Number transformation, then the function you want to use

I'm using Formatter's Perform Math Operation function in the example below. I want to calculate the hours it would take each day to complete an Asana task. I've set up this step to divide the estimated hours for this task by the number of days Formatter calculated earlier. 

Map the Date Compare output in Formatter's Perform Math Operation function.

Now I can use my hours-per-day calculation elsewhere in my Zap. 

Formatter's Math Operation function will provide the calculation result to use elsewhere in a Zap.

Zapier help doc:  Number transformations you can do with Formatter

No matter how you use your Formatter results, remember to test subsequent Zap steps and make sure it's on!

Calculate date-related data confidently with Formatter 

Don't let math mistakes or calendar quirks get in the way of accurate data. With Formatter's Compare Dates function, you can automatically check and calculate dates within your favorite apps. 

Want to automate more of your work with dates and numbers? Check out other ways you can use Formatter:

  • How to change date and time formats in your text automatically

  • Automatically find and match related data across apps

New to Zapier? It's workflow automation software that lets you focus on what matters. Combine user interfaces, data tables, and logic with thousands of apps to build and automate anything you can imagine. Sign up for free.

Get productivity tips delivered straight to your inbox

We’ll email you 1-3 times per week—and never share your information.

tags
mentioned apps

Related articles

Improve your productivity automatically. Use Zapier to get your apps working together.

Sign up
See how Zapier works
A Zap with the trigger 'When I get a new lead from Facebook,' and the action 'Notify my team in Slack'