Expand my Community achievements bar.

Formatting Date using Javascript.

Avatar

Former Community Member

Hi,

I have a date field where the user can enter the date manually or can select from the datepicker.

My problem is, if the user enters date as 6/4/2012, I need to reformat it to 06/04/2012  (DD/MM/YYYY).

I've tried many methods but not sucessfull.

Can anyone please help.

Regards,Raghu.

3 Replies

Avatar

Level 10

You can do that without scripting using Patterns.

Select your date field and then click on Patterns on the Field tab of the Object palette.

The Display pattern is where you set how you want the data to look. You can set up different Edit patterns to accomodate different ways someone might fill the date in. And a Validation pattern to make sure the entered date is correctly formatted.

Radzmar has a great blog post describing all this here:

http://thelivecycle.blogspot.ca/2011/10/date-patterns.html

Avatar

Former Community Member

You can format the date in datepicket widget using this code where you have linked the widget to your form field:

<td><script type="text/javascript">

// BeginOAWidget_Instance_2137022: #datepicker           

                $(function() {

                    $("#datepicker").datepicker({ showOtherMonths: false, dateFormat: 'dd-mm-yy' });

                });

               

// EndOAWidget_Instance_2137022

      </script>

       <input type="text" id="datepicker" />

</td>

Avatar

Level 10

That looks like javascript for html, this is an Adobe LiveCycle discussion group and that code won't work.