Time Based Shortcut

I need to run a shortcut when I connect to CarPlay but not if the time of day is after 4 pm. The shortcut works great but I can’t figure out how to add the “time of day” constraint. Thanks for any input.

1 Like

So this turned out to be easier than I thought. I can’t figure out how to share the full shortcut, but here’s a screenshot of the key part. It should let you do something similar in your shortcut. The key is that the Get Dates From Text action turns out to be smart enough to know what “today” means, and the date conparison’s current date seems to include time.

1 Like

Awesome. Thanks so much. I’ll update my shortcut and see how it works.

If you want to share a shortcut choose at the bottom of your edit screen for the square box with an arrow pointing up. And choose for copy icloud link.

1 Like

Thanks! Very helpful

1 Like

Works. Now the text is only sent before 4pm on weekdays.

1 Like

For future reference and anyone else who wants a is-it-before-or-after-some-time shortcut, here it is.


Enter the comparison time in the text field at the top. It uses the current date and time, and I’ve modified the original to also show if it happens to be exactly the comparison time (4 pm in OP’s request), though I haven’t tested that functionality.

This could obviously be adapted to all sorts of uses, and could be turned into a kind of subroutine that accepts a date or time in text and returns a Boolean result

1 Like

Thanks @tf2! I’ve been trying to figure this out forever. Your discovery that Get Dates From Text is a text parser that understands relative dates was exactly what I needed.

I used your idea to make a time based shortcut called “Is It Between These Times”. Pass it a start and end time parameter and it will return whether the current time is between those two times.

This is especially useful for NFC automations that you want to do different things during different times of the day.

Here’s an example of how to use it in an “Automation”.

1 Like

Great! Glad it’s useful. The way Shortcuts handles dates feels very Apple-y — its a nice touch.

1 Like

New question: Does anyone know how to do other time based calculations. I love the built in date parser that @tf2 found and this parser as well this one however I haven’t found a date parser that can handle commands like this:

  • Next month
  • the 8th
  • the 8th of next month

Toolbox Pro has a neat action that might help, depending what it is you’re actually trying to do: Get Relative Date Description.

I fed it the current date and “next Thursday” and got back “in five days,” which is pretty cool (and accurate). See screen shot — the textblock just said next Thursday and the date was the Current Date automatic variable.

Even better, it looks like Toolbox Pro and/or the built in date functions can do what you want. I built this test shortcut using one of your use cases, and it worked fine.

The two screenshots are sequential.