Skip to main content

Hey Zapier Community folks! Sam from Zapier Support Team here. 



Have you ever wanted to automatically set a date to be the last day of the month but weren’t quite sure how to do it in Zapier? 

Yes? Then read on my friend, because Formatter by Zapier is about to become your best friend!


Ok, so here’s how it’s done. First, we’ll need to add a Formatter (Date / Time > Add/Subtract Time) step and use the {{zap_meta_human_now}} command to add the current date and time as the input.



6f2cf061cd51a2dcf65adcc670982bb6.png

Next, we add 1 month to that date using the expression +1 month. We’ll want to also set the To Format to be MM/YYYY, like so:



9918eb8854d8781b1d1bd0333d541dab.png



This will give us the next month and current year.



If the app step that we’re putting this date in is able to accept the date in DD/MM/YYYY format then great! We can handle it with that by taking the value from that Formatter step and manually adding in the first day of the month as 01/ and use -1d to subtract one day from it to get the last day of the previous month. For example:



f1aeed3bf2bf28e5b2e2d65aa4da85a5.png

But if it needs the format to be in MM/DD/YYYY then we’ll need to add in an additional Formatter step to subtract 1 day using -1 day and convert the format into MM/DD/YYYY. Like so:



2de3f50f840b00f98a2244ae95f990c6.png

Et voilà! 


ea46ab4868534fe11b1df5d7e9a2bd07.png



There you have it, a quick way to get your Zap to automatically output the last day of the current month without needing a more advanced Code step. 


I hope you found this useful. Good luck and happy Zapping!

How can we do this to make sure that we do the last business day of the month?


How can we do this to make sure that we do the last business day of the month?

 

Hmmm...that’s a little trickier, I think. But it sounds like a fun challenge. Lemme see what I can come up with :)


Looks like MM/YYYY is no longer an option for the “To Format” step in the “Date/Time Formatter” action.


How could we do the first of the following month? 


I’ve actually been using a more complex method for this, but one that only requires a single task in Zapier. This is done in a Javascript task. This is pretty basic, it just sets the date to the first of the following month, then removes one day. 

Then you can just reference that output in the following steps. 

If you want to use the first of the following month, just remove the ‘d.setDate(d.getDate() - 1);’ code. 

 

const formatDigits = digit => String(digit).padStart(2, "0"); const d = new Date(); d.setDate(1); d.setHours(0); d.setMinutes(0); d.setSeconds(0); d.setMonth(d.getMonth() + 1); d.setDate(d.getDate() - 1); const day = formatDigits(d.getDate()); const month = formatDigits(d.getMonth() + 1); const year = d.getFullYear(); const lastOfMonth = `${month}/${day}/${year}`; output = { lastOfMonth }];


Reply