1

Am using a datepicker in my application.

code is :

this.$el.find('#ondate').datepicker({
        minDate: 0,
        maxDate: "+2M",
        onSelect: function(x) {
          self.startDepartureValidation();
          return self.onDate(x);
        },
//        numberOfMonths: numberOfMonths,
        beforeShow: function() {
          return $('#ondate').datepicker("option", "maxDate", $("#returndate").datepicker('getDate'));
        }
      });

when i seklect the date am getting the format as MM/DD/YYYY but i need as DD/MM/YYYY in the textbox.

if i use the dateformat: in datepicker i will get that format but , with MM/DD/YYYY am having so many calculations in my application.

Note: i need just in datepicker textbox after seklecting date it should show in that textbox as DD/MM/YYYY. without changing in our code in other places

swe
  • 11
  • 4

1 Answers1

2

Add the dateFormat attribute to your code:

this.$el.find('#ondate').datepicker({
        minDate: 0,
        maxDate: "+2M",
        dateFomat: 'dd/mm/yy', //Note that 'yy' is for four digits.
        onSelect: function(x) {
          self.startDepartureValidation();
          return self.onDate(x);
        },
//        numberOfMonths: numberOfMonths,
        beforeShow: function() {
          return $('#ondate').datepicker("option", "maxDate", $("#returndate").datepicker('getDate'));
        }
      });

More details at the official documentation here.

The below snippet of code can help in converting date format:-

var ddMMyy = $("#ondate").val().split("/");
var mmDDyy = ddMMyy[1]+"/"+ddMMyy[0]+"/"ddMMyy[2];
alert(mmDDyy);

Working JSFiddle here.

Sarath Chandra
  • 1,850
  • 19
  • 40
  • 1
    But with MM/DD/YYYY format i had so many calculations. so, Is there any possibity just i need to show DD/MM/yyyy format in the UI ,but i should collect the format MM/DD/YYYY – swe Jan 05 '16 at 13:11