Hey Danvers! This is totally possible.
Option 1
You can use Google Sheets to calculate the number of days AND to format the dates for you.
Here is how you can set this up within your Zap:
The sheet has a column for the later date, for the earlier date and then one with a formula. Map the dates for the formula right inside the Zap (earlier date, comma, later date).
Notice that I get the data returned by the step (so I can use it in later steps) and I also get the rows added to my spreadsheet. Also, note that one of my dates was formatted and the other wasn't. That's because I changed the formatting for the column in Google Sheets:
So you select the entire column, navigate to what's shown above and create the format that you want. Now, I can send that data somewhere else.
Option 2
1) Another way is to convert the UNIX timestamps into MM/DD/YYYY format with Formatter steps. Then, add a Formatter step using "Numbers" > "Perform Math Operation" > "Subtract" to subtract the later date from the earlier date:
2) Add another Formatter step using "Utilities" > "Spreadsheet-Style Formula" to dive the results by total seconds of day, then round it to the nearest 0 decimal:
3) This provides an output that's the number of days between the UNIX timestamps:
Hope that helps! Also curious to hear how others have approached this and if there is a better way.
You can use this python code as well
@Mews_Zapier - thanks. Any chance you can inline that code for an easy copy/paste experience?
Oh sry, sure,
so in input data at the top (formated as dd/mm/yyyy):
dat1 = {{newer date}}
dat2 = {{older date}}
and then the python code:
import datetime
from datetime import timedelta
datetimeFormat = '%d/%m/%Y'
diff = datetime.datetime.strptime(input_data['dat1'], datetimeFormat)\
- datetime.datetime.strptime(input_datat'dat2'], datetimeFormat)
output = print(diff.days)
Since my last post, we’ve created a better way to do this! The Formatter app now includes a “Compare Dates” Transform that makes this process super simple. You can learn more on exactly how to set this up, here: https://zapier.com/help/create/customize/compare-dates-and-times-in-zaps