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);
    }
});
Sign up to request clarification or add additional context in comments.

7 Comments

I've tried that, but it's doesn't work. When i try that, i can't pick any date on the calendar
dateFormat: "yyyy-mm-dd" should be dateFormat: "yy-mm-dd"
It's still make the whole calendar unselectable
i thisnk there is something else that is breaking your code... check your console for any errors
maybe the problem is minDate and maxDate, should also in format yy-mm-dd.... jsfiddle.net/TRqr9/1
|
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
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.