Telecom

Asterisk Dialplan: Time Conditions (Latest Versions)

MYLINEHUB Team • 2026-02-10 • 10 min

Updated guide for modern Asterisk (PJSIP era): time conditions with real configs, common mistakes, and troubleshooting steps.

Asterisk Dialplan: Time Conditions (Latest Versions)

Time conditions in Asterisk allow you to route calls differently based on the current day and time.

This is not a “small feature” — it is a core requirement in real businesses: office hours, lunch breaks, weekends, holidays, night support, and compliance rules.

This guide explains how to build time-based routing in modern Asterisk (PJSIP) using dialplan, in a way that is clean, scalable, and production safe.

Why Businesses Need Time Conditions

  • Route calls to office phones only during working hours
  • Send calls to voicemail after hours
  • Redirect calls to on-call staff at night
  • Play “closed” announcements on weekends
  • Prevent illegal calling hours for outbound campaigns

Time conditions are also a major part of call center compliance and customer trust.

How Time-Based Routing Works in Dialplan

Asterisk provides a function called:

GotoIfTime()

It allows branching based on time ranges.

Basic Syntax of GotoIfTime()

GotoIfTime(time-range,days-of-week,days-of-month,months?label)

Example:

GotoIfTime(09:00-18:00,mon-fri,*,*?open:closed)

Meaning:

  • If time is between 9 AM and 6 PM
  • And day is Monday to Friday
  • Go to label open
  • Else go to label closed

Example: Inbound Calls During Office Hours

[from-trunk]
exten => s,1,Answer()
 same => n,GotoIfTime(09:00-18:00,mon-fri,*,*?open:closed)

 same => n(open),Playback(welcome)
 same => n,Dial(PJSIP/1001&PJSIP/1002,25,tT)
 same => n,Voicemail(1001@default)
 same => n,Hangup()

 same => n(closed),Playback(company-closed)
 same => n,Voicemail(1001@default)
 same => n,Hangup()

This is a classic business routing pattern.

Example: Weekend Routing

same => n,GotoIfTime(00:00-23:59,sat-sun,*,*?weekend:weekday)

same => n(weekend),Playback(weekend-closed)
 same => n,Hangup()

same => n(weekday),Playback(open-now)
 same => n,Dial(PJSIP/1001,20)
 same => n,Hangup()

Example: Lunch Break Routing

Businesses often want calls during lunch to go to voicemail or a backup agent.

same => n,GotoIfTime(13:00-14:00,mon-fri,*,*?lunch:normal)

same => n(lunch),Playback(agents-at-lunch)
 same => n,Voicemail(1001@default)
 same => n,Hangup()

same => n(normal),Dial(PJSIP/1001&PJSIP/1002,25)
 same => n,Hangup()

Time Zone Considerations (Critical in Cloud Deployments)

Time conditions depend on the server time zone. Confirm Linux timezone:

timedatectl

If you run Asterisk in cloud but business is in India, set timezone correctly:

sudo timedatectl set-timezone Asia/Kolkata

Incorrect timezone is a common reason time conditions “fail”.

Call centers must avoid dialing after restricted hours. Example: only allow outbound from 10 AM to 7 PM.

[outbound]
exten => _9.,1,GotoIfTime(10:00-19:00,mon-sat,*,*?allowed:notallowed)

 same => n(allowed),Set(NUM=${EXTEN:1})
 same => n,Dial(PJSIP/${NUM}@trunk,60)
 same => n,Hangup()

 same => n(notallowed),Playback(calling-not-allowed-now)
 same => n,Hangup()

This prevents compliance violations and builds trust.

Holidays and Special Days (How to Handle Cleanly)

Asterisk dialplan supports time ranges, but a real holiday list is easier to maintain using:

  • Asterisk database (AstDB)
  • External API or AGI
  • CRM-driven schedule config

Simple AstDB approach:

same => n,Set(IS_HOLIDAY=${DB(holidays/${STRFTIME(${EPOCH},,%Y-%m-%d)})})
same => n,GotoIf($["${IS_HOLIDAY}"="1"]?closed)

This allows a human admin to set holiday days without editing dialplan.

Common Time Condition Problems and Fixes

Time Condition Never Matches

  • Server timezone is wrong
  • Day range typed incorrectly
  • Using 24-hour format incorrectly

Calls Route Wrong on Weekends

  • Misconfigured mon-fri logic
  • Using “sat-sun” incorrectly

Debug by printing server time:

same => n,NoOp(Now is ${STRFTIME(${EPOCH},,%c)})

Best Practice: Put Time Logic in a Dedicated Context

Instead of repeating time checks everywhere:

[inbound-router]
exten => s,1,GotoIfTime(09:00-18:00,mon-fri,*,*?open:closed)
 same => n(open),Goto(inbound-open,s,1)
 same => n(closed),Goto(inbound-closed,s,1)

This keeps dialplan clean and scalable.

Key Takeaway

Time conditions are essential for real telecom operations. They protect: customer experience, compliance, and operational discipline.

Use GotoIfTime() for simple time windows, and use database/API-based logic for holiday and advanced scheduling.

A well-designed time routing system is a sign of a mature call center architecture.

Try it

Want to see API-driven CRM + Telecom workflows in action? Try the WhatsApp bot or explore the demos.

💬 Try WhatsApp Bot ▶️ Watch CRM YouTube Demos
Tip: Comment “Try the bot” on our YouTube videos to see automation in action.
M
MYLINEHUB Team
Published: 2026-02-10
Quick feedback
Was this helpful? (Yes 0 • No 0)
Reaction

Comments (0)

Be the first to comment.