Home » Azure Functions – Time Trigger (CRON) Cheat Sheet

Azure Functions – Time Trigger (CRON) Cheat Sheet

This is a cheat sheet for CRON expressions that are used in the time triggers for Azure functions. They define how often a trigger/the Azure function should be executed (daily, hourly, every 3 months, …).

The basic format of the CRON expressions in Azure is:
{second} {minute} {hour} {day} {month} {day of the week}
e.g. 0 * * * * * (=every minute)

The following values are allowed for the different placeholders:

Value Allowed Values Description
{second} 0-59; * {second} when the trigger will be fired
{minute} 0-59; * {minute} when the trigger will be fired
{hour} 1-23; * {hour} when the trigger will be fired
{day} 1-31; * {day} when the trigger will be fired
{month} 1-12; * {month} when the trigger will be fired
{day of the week} 0-6; MON-SUN; * {day of the week} when the trigger will be fired

e.g. 3 5 * * * * defines a trigger that runs every time when the clock is at second 3 and minute 5 (e.g. at 09:05:03, 10:05:03, 11:05:03, …).

The trigger executes at UTC timezone. So for Vienna (UTC+1), a trigger at 18:00 (UTC) executes at 19:00 Vienna time (UTC+1).

Examples

Expression Description runs at
0 * * * * * every minute 09:00:00; 09:01:00; 09:02:00; … 10:00:00
0 */5 * * * * every 5 minutes 09:00:00; 09:05:00
0 0 * * * * every hour (hourly) 09:00:00; 10:00:00; 11:00:00
0 0 */6 * * * every 6 hours 06:00:00; 12:00:00; 18:00:00; 00:00:00
0 0 8-18 * * * every hour between 8-18 08:00:00; 09:00:00; … 18:00:00; 08:00:00
0 0 0 * * * every day (daily) Mar 1, 2017 00:00:00; Mar 2, 2017 00:00:00
0 0 10 * * * every day at 10:00:00 Mar 1, 2017 10:00:00; Mar 2, 2017 10:00:00
0 0 * * * 1-5 every hour on workdays Mar 3 (FRI), 2017 22:00:00; Mar 3 (FRI), 2017 23:00:00; Mar 6 (MON), 2017 00:00:00
0 0 0 * * 0 every sunday (weekly) Mar 5 (SUN), 2017 00:00:00; Mar 12 (SUN), 2017 00:00:00
0 0 9 * * MON every monday at 09:00:00 Mar 6 (MON), 2017 09:00:00; Mar 13 (MON), 2017 09:00:00
0 0 0 1 * * every 1st of month (monthly) Mar 1, 2017 00:00:00; Apr 1, 2017 00:00:00; May 1, 2017 00:00:00
0 0 0 1 1 * every 1st of january (yearly) Jan 1, 2017 00:00:00; Jan 1, 2018 00:00:00; Jan 1, 2019 00:00:00
0 0 * * * SUN every hour on sunday Mar 5 (SUN), 2017 23:00:00; Mar 12 (SUN), 2017 00:00:00; Mar 12 (SUN), 2017 01:00:00
0 0 0 * * SAT,SUN every saturday and sunday Mar 3 (SUN), 2017 00:00:00; Mar 11 (SAT) 00:00:00; Mar 12 (SUN), 2017 00:00:00
0 0 0 * * 6,0 every saturday and sunday Mar 3 (SUN), 2017 00:00:00; Mar 11 (SAT) 00:00:00; Mar 12 (SUN), 2017 00:00:00
0 0 0 1-7 * SUN every first sunday of the month at 00:00:00 Mar 5 (SUN), 2017 00:00:00; Apr 2 (SUN), 2017 00:00:00
11 5 23 * * * daily at 23:05:11 Mar 1, 2017 23:05:11; Mar 2, 2017 23:05:11
30 5 /6 * * * every 6 hours at 5 minutes and 30 seconds 06:05:30; 12:05:30; 18:05:30; 00:05:30
*/15 * * * * * every 15 seconds 09:00:15; 09:00:30; … 09:03:30; 09:03:45; 09:04:00

(the most common expressions are bold)

Attention: the following CRON expression is valid and you can use it, but there is an issue with it:
0 0 */5 * * *
It means every 5 hours. It executes at: 00:00:00, 05:00:00, 10:00:00, 15:00:00. 20:00:00, 00:00:00 …
So it’s not exactly every 5 hours. So it should be dividable by the maximum value. The following values are good if you want a regular frequency:

  • for minutes and seconds: /2, /3, /4, /5, /6, /10, /12, /15, /20 and /30 (60 is divisible by these numbers)
  • for hours: /2, /3, /4, /6, /8 and /12
  • for months: /2, /3, /4 and /6
  • for days: nothing, because there are leap years and months with 28, 29, 30 or 31 days.

All other values can lead to “wrong” executions at the end of a “cycle”. e.g. every 7 hours executes at 00:00, 07:00, 14:00, 21:00, 00:00 (only 3 hours – not 7)

Additional information

Azure Functions timer trigger: https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer
Wikipedia CRON expression: https://en.wikipedia.org/wiki/Cron#CRON_expression
Working with Azure functions (part 1 – Powershell): https://codehollow.com/2016/11/working-azure-functions-part-1-powershell/
Working with Azure functions (part 2 – C#): https://codehollow.com/2016/11/working-with-azure-functions-part-2-c/
CRON Expression Descriptor: http://cronexpressiondescriptor.azurewebsites.net/

3 comments

    • Armin Reiter says:

      Good question – I added it to the samples above. I would construct it as:
      0 0 0 1-7 * SUN
      At 0 seconds, 0 minutes, 0 hours on 1st, 2nd, …. or 7th day of the month on sundays. So at 00:00:00 on sunday with “day of month” between 1 and 7.

Leave a Reply

Your email address will not be published. Required fields are marked *