Collecting Date and Time

Collecting date and time through an IVR application is a common requirements and many developers have posted questions about how to write VoiceXML code that collects this information.  The following IVR code example collects the day of the week and (universal) time of of day.  It can be used with any VoiceXML app.

<?php
header(“Content-type: text/xml”);
echo(“<?xml version=”1.0″?>n”);
?>
<vxml version=”2.0″>
<form>
<script>
var currentDate = new Date();
var month = currentDate.getMonth() + 1;
var day = currentDate.getDate();
var year = currentDate.getFullYear();
currentDate = month + “/” + day + “/” + year;

var currentTime = new Date();
var hour = currentTime.getUTCHours();
var minute = currentTime.getUTCMinutes();
</script>
<block>
<prompt>
The date is <value expr=”currentDate”/>. The universal time is <value expr=”hour”/> hours and <value expr=”minute”/> minutes.
</prompt>
</block>
</form>
</vxml>

Here’s a link to reference Date objects: http://www.w3schools.com/jsref/jsref_obj_date.asp

Share this with friends!twittergoogle_pluslinkedin