Upgrade 3CX to v18 and get it hosted free!

Asterisk tips openhours

Author image

How to include contexts based on time and date

The Asterisk dial plan, extensions.conf lets you include contexts based on time and/or date.

Syntax:

include => <context>,<times>,<weekdays>,<mdays>,<months>

Example:

; First, let’s do the holidays.
include => holiday,*,*,1,jan
include => holiday,*,*,31,may
include => holiday,*,*,4,jul
include => holiday,*,*,6,sep
include => holiday,17:00-23:59,*,24,nov
include => holiday,*,*,25,nov
include => holiday,17:00-23:59,*,24,dec
include => holiday,*,*,25,dec
include => holiday,17:00-23:59,*,31,dec

; These are the days we’re open.
include => day,09:00-19:59,mon-fri,*,*
include => day,10:00-14:59,sat,*,*

; If we’re not open, we’re closed.
include => night

Example from Troy Settle


I ran into a problem with this. The night context is always included in this scenario, and if the night context contains the same extensions as the day context, Asterisk will continue with the night context if the extensions match:

[day]
exten => s,8,BackGround(to-hear-menu-again)

will jump to:

[night]
exten => s,9,BackGround()

To prevent this, specify an explicit night include:

include => night,20:00-8:59,mon-fri,*,*
include => night,15:00-9:59,sat,*,*
include => night,*,sun,*,*

Article Reviews

Write a Review

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

Required Field. Minimum 5 characters.

Required Field. Minimum 5 characters, maximum 50.

Required field.There is an error with this field.

Required Field.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

There are no reviews for this article. Be the first one to write a review.

Related Posts:

Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.