${CDR(duration)}

Im trying to record call times to a text file but it just enters a zero. how do I get ${CDR(duration)} to work? ${CDR(callend)} also dosnt work, I have a line that sets it as the current time of hangup.

exten => h,1,Set(saveto=/var/www/html/logs/); where to save the file exten => h,n,Set(filename=${CONTEXT}.txt); what to call the file exten => h,n,Set(callend=${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)}); exten => h,n,System(echo "${STRFTIME(${EPOCH},,%a %b %d | %I:%M %p)} | ${CALLERID(num)} | ${CALLERID(name)} | ${CDR(duration)} | ${CDR(start)} | ${CDR(answer)} | ${callend}" >> ${saveto}${filename}) ; exten => h,n,Hangup

To do this you will need to add “endbeforehexten=yes” to cdr.conf:

Normally, CDR’s are not closed out until after all extensions are finished
executing. By enabling this option, the CDR will be ended before executing
the “h” extension so that CDR values such as “end” and “billsec” may be
retrieved inside of of this extension.