Page 1 of 1

Define date format

Posted: Wed Jul 02, 2008 3:35 am
by soso
Hi,

I'm newbie on this forum and vxml language. I've a question.

By default, the date format is under Wed Jul 02 2008 10:15:59 GMT+0200, with this code:

Code: Select all

<var name="startDate" expr="Dat()"/>
I would like to create the date with mm/dd/yy.

How do I proceed?

Thanks by advance.

IVR code to format date

Posted: Wed Jul 02, 2008 11:25 am
by support
Hi,

You can use this IVR code to achieve the date format that you are looking for. Note what's inside of the IVR tag, <script>.

Code: Select all

<?xml version="1.0"?>
<vxml version="2.0">
  <form>
    <script>
      var currentTime = new Date();
      var month = currentTime.getMonth() + 1;
      var day = currentTime.getDate();
      var year = currentTime.getFullYear();
      currentTime = month + "/" + day + "/" + year;
    </script>
    <block>
      <prompt>
        The date is <value expr="currentTime"/>.
      </prompt>
    </block>
  </form>
</vxml>
Hope this helps.

Regards,
Plum Support

Posted: Wed Jul 02, 2008 12:10 pm
by soso
Thanks for your answer.

Why can i may +1 in the month var?

Clarification of IVR code for date format

Posted: Wed Jul 02, 2008 1:07 pm
by support
You have to add + 1 because the getMonth() function for the Date object returns the number of month from 0-11.

See here for more IVR information on the Date object:

http://www.tizag.com/javascriptT/javascriptdate.php

Regards,
Plum Support

Posted: Wed Jul 02, 2008 1:08 pm
by soso
Ok, very thanks.