Search code examples
jquery-uiuidatepicker

how to get the value of jQuery datepicker in dateFormat?


I have a jQueryUI datepicker, which was created with dateFormat: 'dd/mm/yy'. If I use a regular HTTP POST or HTTP GET request, the input is passed effectively in dd/mm/yy format, but when I use the datepicker's getDate method in any script, I get something like 'Wed Oct 05 2011 00:00:00 GMT-0430 (Venezuelan Standard Time)'.

Is there a way I could get the date in the dateFormat of the datepicker (or any format)?

Of course I could use the value of the text input that contains the datepicker, but I would prefer using a method from the widget.


Solution

  • getDate() should be returning a JavaScript Date object, so any of the Date methods should work for you.

    I.E.

    var date = $("#yourId").datepicker('getDate');
    console.log(date.getDay()); //Returns day of the week 0-6
    console.log(date.getDate()); //Returns day of the month 1-31
    //etc...
    

    Date Object Reference