Welcome back, Zappers! This is our 5th installment in the Formatter Features series and today we’re going to be looking at how to use Formatter to alter date formats. Missed the first five? You can check them out here:
What We’ll be Covering
Fixing dates that are in the wrong format
Dates aren’t always sent from one app in a format that other apps are expecting, which can cause the day and month values to be swapped around!
Custom Date Formats
There may be times when the date format you need isn’t one of options available to select, so you’ll need to use custom date variables to create a custom date format.
Extracting the time from a date
Sometimes we’ll receive both a date and time value in a field, but we only need the time. With a Formatter step we reformat it to extract just the time.
Converting Unix timestamps into readable dates
Unix timestamps are a nice way for a computer to reference a date and time in seconds, but for us humans, they aren’t so easy to understand!
How to use Formatter to adjust date formats
Passing dates between apps that use different date formats can be tricky but Formatter is here to help with that! You can find it under Formatter by Zapier > Date / Time > Format:
Fixing dates that are in the wrong format
Ever see strange behaviour in your Zap where the day and the month are swapped around? This can occur when the date is being sent in a format that the app receiving it isn’t expecting.
A good fix for this is to convert from the date its receiving to the date format it’s expecting. For example, change DD/MM/YYYY to MM/DD/YYYY.
To do that, in the To Format field you’d select the format that you want to change the date to (eg MM/DD/YYYY):
And in the From Format field, you’ll select the format you want to change it from (eg DD/MM/YYYY):
This would convert a date of 20/09/2021 into 09/20/2021:
Custom Date Formats
Don’t see the format you want listed? You can select the Custom option from the dropdown menu and type in your own custom date format directly into the field:
You can see a full list of the custom date variables available to use in Date/Time custom value table. And you can read more about how to use a custom value in a Zap here:
Add custom values to dropdown menu fields in Zaps
Extracting the time from a date
To remove a date from a field that contains both a date and a time, you’d first select the From Format that matches the format of the date in the Input field. Then use the Custom option to enter the desired time only format.
For example, if the input date was 2021-07-21T07:59:55+00:00 and we just wanted the time as 07:59, we’d use a custom date format of hh:mm in the To Format field:
Then in the From Format field we’d select the YYYY-MM-DDTHH:mm:ssZ (2006-01-22T23:04:05-0000) format:
That would then give us the time value only:
Converting Unix timestamps into readable dates
Sometimes an app will send dates as Unix timestamp. These will appear as a string of numbers like 1626854395.
To convert a date from a Unix timestamp into a format that’s a bit easier to understand, like MM/DD/YYYY, you’d select the To Format of MM/DD/YYYY (01/22/2006):
Then select the From Format of X (1137971045):
That would convert a Unix timestamp of 1626854395 into 07/21/2021:
Things to Remember
Something to be mindful of is that Formatter will do it’s best to interpret the format it’s receiving the date in when a From Format isn’t selected, but it doesn’t always get it right. Be sure to select the correct From Format to ensure dates are interpreted correctly.
It’s also worth noting that when no timezone has been selected, Formatter will automatically assume that it needs to use UTC time. So if UTC isn’t what you’re using make sure you select the desired timezone on the To Timezone and From Timezone fields.
Other Resources
If you’re looking for more information, here are a few places you can look:
- Community articles
- Zapier’s help docs (here + here)
- This video from the first version of Zapier University
Wrapping Up
In our next article, we’ll be looking at how to compare dates together as well as how to add and subtract days using Formatter! :)