Formatter Features: Date Add/Subtract & Compare
Hey again, Zappers! Nick here, from the Community team. I’ll be taking you through some date-related features of Formatter by Zapier.
Dates come in many formats, and the various apps you're using may not line up nicely with one another. Sometimes you have time zones to contend with, or maybe you need to figure out how many days between two dates.
Today we’ll be looking at the following:
-
Date Add/Subtract
-
Compare Dates
Date Add/Subtract
This option can be found at:
Formatter by Zapier — Date/Time — Add/Subtract Time
What It Looks Like
What It Can (and Can't) Do
Before you start to make assumptions or get your hopes up, let's briefly cover what is and is not possible with Add/Subtract Time.
Things you can do with this transform option:
-
Add/subtract months, days, or hours to a given date
-
Change the format for the finalized date
-
Specify the precise format for the incoming date
Things you can not do with it:
-
Process multiple dates at a time (line items not supported)
Some Ways to Use It
1) Specify an End Date Based on a Start Date
Let's say you're selling a subscription or membership and your trigger provides the start date and the amount of time the person has signed up for. You could use Add/Subtract Time to generate the end date:
Example: "Your subscription starts today sinsert the date] and will end on insert the output of the Formatter step]."
2) Calculate Times Based on Timezones
Your trigger step might provide a date/time for a single timezone but you need to output one or more different time zones (maybe based on a form submission). Depending what a person has specified, or you can get from metadata automatically, you could add the appropriate number of hours.
Trigger: Form Submission (for example)
Action: Formatter — Utilities — Lookup Table (to take form field — Eastern Standard Time — and output number of hours)
Action: Formatter — Date/Time — Add/Subtract Time (take initial date/time and add output of Lookup Table)
Action: App of Choice, including the output of that previous Formatter step.
3) Generate End Time of An Appointment/Consultation
Maybe you've got a booking app that lets people choose a start time for an appointment and then the length of time they'd like, but the app doesn't give you the end time. Much like Example #1 above, you could generate the end time of the appointment.
Example: "Your appointment has been scheduled for sinsert date from app]. It starts at mtime from app] and ends at routput of Formatter step where you added start time plus length of appointment]".
Anything Tricky About It?
Like any Formatter step that uses dates/times you'll want to make sure that you use the From Format field if you're not getting the results you want. We try our best to parse the date but in some cases we may not be able to do it if the format is atypical.
Make sure that you format the expression as specified. If you don't, you likely won't get the desired result.
Yes: -2 days, +1 month, +7 hours 25 minutes
No: - 2 days, - 2days, +1month, + 1 month, + 7hours 25minutes
Compare Dates
This option can be found at:
Formatter by Zapier — Date/Time — Compare Dates
What It Looks Like
What It Can (and Can't) Do
I'd hate for you to start building a Zap without knowing what is and is not possible with the Compare Dates transform.
Things you can do with this transform option:
-
Enter two dates and get the days, hours, minutes, seconds between them
-
Check whether two dates are the same
-
Specify the precise format for the start date and the end date
Things you can not do with it:
-
Compare more than two dates
-
Use line items to process multiple sets of dates
-
Adjust dates by using something like +1d
Some Ways to Use It
Filter on Whether Both Dates are the Same
There are times when you want to continue (or stop) a Zap based on whether two dates match. Since the Compare Dates step will tell you if they match, you can filter on that with a boolean (true/false) in the Filter step.
Example 1: What if you want to know whether a scheduled delivery date matches tomorrow's date, and if it does, you want to send a notification to the customer?
NOTE: Since Compare Dates does not yet support the adjustment of dates by using a modifier like +1d, you'd have to first use the Add/Subtract step (as shown at the beginning of this article.
You can see here that it's an exact match, since days, hours, minutes and seconds are 0.
Example 2: Maybe you don't want to allow someone to change their username if their creation date is the same as today's date. If the trigger provides the first date, you can use {{zap_meta_human_now}} as today's date.
When we test, we can see that the dates do match. We also see that the difference between them is 15 hours and 18 minutes, because one of them contains the time and the other does not (so we calculate it as the very beginning of the day).
Get the Number of Hours Between Now and Start Time
I'm using hours here but it could just as easily be days, minutes or seconds. Maybe you're sending out emails hyping an upcoming event and you want to know how much time there is at that exact moment, between the start time and when you send the email.
When we test the step, we get the output of 2.
We could map this into the body of an email:
"Are you excited?! The event starts in ioutput of Formatter step] hours! See you there :)"
Anything Tricky About It?
As mentioned in the section about what it can NOT do, you can't modify the date/time directly within the step. So if you want to compare a date with one that is X days/hours/minutes in the past or future, you'll need that extra step.
Just as with the Add/Subtract Time feature, if you're not getting the result you're expecting when you test, make sure to use the correct date formats here:
Coming Up in the Series
Next up in the Formatter Features series we'll be taking a look at currency + number formatting
and how you can use these features in your Zaps. Until next time!