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
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
});
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly