How can I change format of jQuery Datepicker date?


I have a basic question, which I am not able to understand, How to format the date of jQuery datepicker in mm-dd-yyyy?

Here is my code

<input type="text" id="datePicker" />

jQuery code

$('#datePicker').datepicker();

Need output date text in MM-dd-yyyy format, how to achieve it, thanks


Asked by:- Vinnu
0
: 2034 At:- 4/25/2018 2:35:32 PM
jQuery jQuery UI jQuery Datepicker format







1 Answers
profileImage Answered by:- pika

When you create a datepicker, you have not mentioned any date format so you just need to mention date format also, while initializing datepicker in any input textbox, so for your above input box, jQuery code will be

$('#datePicker').datepicker({
   dateFormat: 'mm-dd-yy' //your date format
});

For other date formats, you can change jQuery code as per your need

$('#datePicker').datepicker({
   dateFormat: 'dd/mm/yy' //your date format
});

Output:

27/04/2017

Similarly for short  date “d M, y” 

$('#datepicker').datepicker({
    dateFormat: 'd M, y' //output 27 April, 17
});

For showing full date, your date format will be  'DD, d MM, yy'

$('#datepicker').datepicker({
    dateFormat: 'DD, d MM, yy' //Friday, 27 April, 2018
});
2
At:- 4/27/2018 7:42:34 AM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use