Delaying a Zap until a specific time of day

  • 20 September 2019
  • 3 replies
  • 4161 views

Userlevel 7
Badge +11

Let's say that you have a Zap with any trigger, but you don't want the actions of the Zap to continue until a specific time of day. Perhaps you have an SMS service and you want to send the first message at 12pm after someone signs up, or maybe you want to gather all your new leads that come in throughout the day and send them to yourself at 7am every day.


You can't do this with just one Delay step as 'Delay until' requires a specific date as well as time. So - taking the last example - you need one delay for if it's before 7am (to continue the Zap today at 7am) and one if it's after (to continue the Zap tomorrow at 7am).

Thankfully you can do this pretty easily using the Formatter by Zapier app and a couple of paths.


After the trigger step, add the Formatter step. Choose to work with Date/Time and then select the Format option.

In the 'Input' field type: {{zap_meta_human_now}}

Whenever you type that in a Zap, it creates a timestamp of whatever date and time it was when the action runs.

For the 'To Format', select 'Use a Custom Value' and in the Custom value box, type HH

Screenshot of Formatter step showing the

You can then use the output of that Formatter step to create Path rules that run depending on whether it's before 7am or after.

Here's a screen recording showing how that looks in a Zap:

Screen Recording 2018-09-19 at 03.28 PM.mov

This is similar to some of the answers to @jesse's question 'How can How can I create a Zap/workflow that only runs during business hours?' though a little simpler as we're only looking at the time of day and not the day as well.


I wonder if anyone has a neat way of doing this without using Paths?



3 replies

Userlevel 7
Badge +10

A code step gets you there without Paths.

Start with a small change to the formatter step:

Screen Shot 2019-09-20 at 17.56.56.png

Then you want this Javascript code step (code to copy/paste below):

Screen Shot 2019-09-20 at 17.58.35.pngtimeNow = output of formatter step

timeUntil = time you're checking against in H format (i.e no training 0, so 9 not 09)

The output will be one of two phrases - in this example:

"17:00" or "17:00 Tomorrow"... which you can then map into your delay stage:

Screen Shot 2019-09-20 at 18.02.54.pngDone 😀

var timeNow = parseInt(inputData.timeNow, 10);

var timeUntil = parseInt(inputData.timeUntil, 10);

if (timeNow < timeUntil) {

return {outcome: timeUntil + ':00'};

}

else if (timeNow >= timeUntil) {

return {outcome: timeUntil + ':00 Tomorrow'};

}


Userlevel 3

Hi @Danvers,

I recently wrote a post to do this without Paths, and provides a little more customization in an easy way (as code can be tricky). Here’s the link: https://community.zapier.com/tips-and-inspiration-5/make-a-zap-work-between-mon-sat-from-8am-to-6pm-otherwise-delay-1659

 

Cheers,

Userlevel 3
Badge

To accomplish this, I’d use JavaScript to obtain the next workday (Mon-Fri) which is not a public holiday - using the AbstractAPI Holidays API. The pricing is cheap-to-reasonable and the programming is pretty trivial. I’d use that information to feed a date to Delay, and the job is done.

  1. while date is not mon-fri OR abstractAPI for that date returns holiday
    1. increment date (using setDate on the date object)
  2. return date

 

Reply