Understanding CRON Expressions

I'm a software consultant who loves to build projects and share my learnings on this blog.
Search for a command to run...

I'm a software consultant who loves to build projects and share my learnings on this blog.
No comments yet. Be the first to comment.
Azure Functions is a powerful serverless compute platform, and Azure App Service handles a lot of the underlying configuration for you out of the box. However, there are scenarios where you may want t

If you’ve been exploring Azure AI learning paths or watching older demos, you’ve probably run into something confusing: The documentation and training links often reference Foundry (Classic) But the portal you’re using today might show Foundry (New...

In today's digital age, speed is paramount for web and mobile applications. Users expect instantaneous responses, and any delay can lead to a poor user experience and loss of engagement. Therefore, as developers, it's crucial to build web APIs that a...

Loops are fundamental constructs in any programming language. But have you ever wondered if there are any performance differences between them? For small collections, the difference might be negligible, but what about handling a million or 10 million...

When using an Azure Function app, it is necessary to connect it to a storage account, often referred to as Host storage. This storage is utilized by the Functions runtime, as well as by various triggers and bindings to coordinate between multiple run...

Many Azure resources like web jobs, Azure functions, logic apps use CRON expression when they need to work with Time Triggers. A CRON expression lets you define a time trigger with the help of six fields. All the possible time triggers let it be 'Once an hour' to '14 times a day' can be defined using a CRON expression.
As mentioned earlier, a CRON expression includes six fields:
{second} {minute} {hour} {day} {month} {day-of-week}
And each field can have one of the following values:
| Type | Example | Triggered |
| Specific Value | 0 5 * * * * | At every hour at that hour past 5 minutes |
| All Values (*) | 0 * 5 * * * | At the 5th hour of day (05:mm:00), trigger it every minute of the hour |
| A range ( - ) | 8-10 * * * * * | At hh:mm:08,hh:mm:09,hh:mm:10 where hh:mm is every minute of every hour. 3 times a minute at 8,9,10th second |
| A set ( , ) | 1,5,25 * * * * * | At hh:mm:01, hh:mm:05, hh:mm:25 where hh:mm is every minute of every hour. 3 times a minute at 1, 5, 25th second |
| An Interval ( / ) | 0 */5 * * * * | At hh:05:00, hh:10:00, hh:15:00 and so on till hh:55:00, hh:00:00 where hh is every hour. 12 times an hour |
Some of the frequently used CRON expression samples
| Expression | Triggered |
| */10 * * * * * | Every 15 seconds |
| 0 * * * * * | Every minute |
| 15 * * * * * | Every minute at 15th Second of that minute |
| 0 */10 * * * * | Once every 10 minutes |
| 0 0 * * * * | Once every hour at 0th minute |
| 0 0 */4 * * * | Once every 4 hours |
| 0 0 9-17 * * * | Once every hour from 9AM to 5pm |
| 0 0 0 * * * | Every day at 00:00:00 |
| 0 30 10 * * * | at 10:30 am every day |
| 0 30 10 2 * * | at 10:30 am every 2nd day of every month |
| 0 30 10 * * 0,6 | at 10:30 am every weekend (Sat, Sun) |
| 0 30 10 * * 1-5 | at 10:30 am every weekday |
| 0 0 * * * WED,FRI | Every hour on Wednesday and Friday |
| 0 0 0 * * SUN | Every Sunday at 00:00:00 |
| 0 0 0 1-7 * SUN | Every first Sunday of the month at 00:00:00 |
| 0 0 0 1 * * | Every 1st of month at 00:00:00 |
| 0 0 0 1 1 * | Every 1st of January every year |
| 0 0 * * 1 * | Every hour in January |
| 30 5 */6 * * * | Every 6 hours at 5 minute 30 seconds |
The CRON expression 0 0 */5 * * * means every 5 hours. So 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. If you want a regular frequency, the following expressions are good:
If you want a cyclic approach, all other values can lead to "wrong" executions at the end of the cycle. e.g. Every 10 hours executes at 00:00:00, 10:00:00, 20:00:00, 00:00:00 (only 4 hours, not 10).
You can find CRON expression examples online, but many of them omit the {second} field. In case you copy one of them, remember to add the missing {second} field. Also, you will want a zero in that field and not an asterisk
Time trigger for Azure Functions: https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer
CRON Expression Descriptor: https://cronexpressiondescriptor.azurewebsites.net/