3

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 :-)

2 Answers 2

3

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);
    }
});
7
  • I've tried that, but it's doesn't work. When i try that, i can't pick any date on the calendar
    – Dennis
    Commented Aug 1, 2013 at 9:50
  • dateFormat: "yyyy-mm-dd" should be dateFormat: "yy-mm-dd"
    – user405398
    Commented Aug 1, 2013 at 9:51
  • It's still make the whole calendar unselectable
    – Dennis
    Commented Aug 1, 2013 at 9:52
  • i thisnk there is something else that is breaking your code... check your console for any errors
    – bipen
    Commented Aug 1, 2013 at 9:53
  • maybe the problem is minDate and maxDate, should also in format yy-mm-dd.... jsfiddle.net/TRqr9/1
    – dann
    Commented Aug 1, 2013 at 10:03
0

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
}
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.