Dennis
Dennis

Reputation: 29

format date in jQuery UI datepicker

I use the datepicker from jQuery UI, but the format is like example today: 08/01/2013

But i want the format to be example today: 2013-08-01

Here is code line i think maybe i should use?

`$( "#txtFromDate" ).datepicker( "option", "dateFormat", "yyyy-mm-dd" );`

And here is my jQuery code i use that works fine but don't know where to put the line? And i want the format in both of my fields.

`
$(document).ready(function(){
    $("#txtFromDate").datepicker({
        minDate: "07/17/2012",
        maxDate: "0D",
        numberOfMonths: 2,
        onSelect: function(selected) {
          $("#txtToDate").datepicker("option","minDate", selected);
        }
    });
    $("#txtToDate").datepicker({ 
        minDate: "07/17/2013",
        maxDate:"0D",
        numberOfMonths: 2,
        onSelect: function(selected) {
           $("#txtFromDate").datepicker("option","maxDate", selected);
        }
    });  
});`

I hope somebody have a solution for this :-)

Upvotes: 3

Views: 9444

Answers (2)

Bindiya Patoliya
Bindiya Patoliya

Reputation: 2764

You can directly set the date format from jquery-ui library,that's work for me.hope for you also

in

function Datepicker()
{
  //other code
  dateFormat: "yy-mm-dd", // See format options on parseDate 
  //other code
}

Upvotes: 0

bipen
bipen

Reputation: 36531

since your already have other options in the datepicker... add it there.

try this

$("#txtFromDate").datepicker({
    minDate: "07/17/2012",
    maxDate: "0D",
    numberOfMonths: 2,
    dateFormat: "yy-mm-dd", //<----here
    onSelect: function(selected) {
      $("#txtToDate").datepicker("option","minDate", selected);
    }
});

Upvotes: 3

Related Questions