For calculating the difference between two times in Asterisk dialplan, the time values should be converted to an epoch value first. This can be done using the asterisk function STRFTIME. Use the below dialplan to convert current time to an epoch value
Set(time=${STRFTIME(${EPOCH},,%s)})
B0elow dialplan shows, Asterisk setting two variables starttime
and endtime
with the current time in an interval of 10 seconds and then calculating the difference between the variables and saving to variable diff
. The output of variable diff
will always be 10 in the below dialplan:
exten => 1000,1,Set(starttime=${STRFTIME(${EPOCH},,%s)})
same => n,Wait(10)
same => n,Set(endtime=${STRFTIME(${EPOCH},,%s)})
same => n,Set(diff=$[${endtime} -${starttime}])
same => n,Hangup()