Aaron
Aaron

Reputation: 434

jquery datepicker not formatting the date

All I want is for the date to be in dd/mm/yyyy format when it is inserted into the input box but it comes through as the default mm/dd/yyyy. When I insert the date into the input with $("#midmonthstart_"+uid).val(formated); I have read on the API docs that will format it, but I have got something wrong here.

function selectmiddate(uid){
$("#midmonthstart_"+uid).datepicker({
    format:'d/m/Y',
    date: $("#midmonthstart_"+uid).val(),
    current: $("#midmonthstart_"+uid).val(),
    starts: 1,
    position: 'r',
    onBeforeShow: function(){
        $("#midmonthstart_"+uid).DatePickerSetDate($("#midmonthstart_"+uid).val(), true);
    },
    onChange: function(formated, dates){
        $("#midmonthstart_"+uid).val(formated);
        $("#midmonthstart_"+uid).DatePickerHide();
    }
});
}

Upvotes: 0

Views: 105

Answers (1)

janilemy
janilemy

Reputation: 565

You should write :

function selectmiddate(uid){
$("#midmonthstart_"+uid).datepicker({
    dateFormat:'dd-mm-yy',
    date: $("#midmonthstart_"+uid).val(),
    current: $("#midmonthstart_"+uid).val(),
    starts: 1,
    position: 'r',
    onBeforeShow: function(){
        $("#midmonthstart_"+uid).DatePickerSetDate($("#midmonthstart_"+uid).val(),     true);
    },
    onChange: function(formated, dates){
        $("#midmonthstart_"+uid).val(formated);
        $("#midmonthstart_"+uid).DatePickerHide();
    }
  });
}

See the documentation:

http://api.jqueryui.com/datepicker/#option-dateFormat

Upvotes: 2

Related Questions