Here is my code:
$(function () {
$(\"#datepicker\").datepicker({ dateFormat: \'DD-MM-YY\' });
});
And the datetime picker is shown, but
try out this
$(".datepicker").datepicker({dateFormat: 'dd-mm-yy'});
small letter will works
Depending on the version of datepicker being used, the correct format may be:
$('#datepicker').datepicker({ format: 'yyyy-mm-dd' });
If you're getting the default date value from your backend framework/service, i.e., Asp.Net MVC
, setting the dateFormat
when you initiate the datepicker
on your input won't format the date initially.
$(function() {
$('#date-start').datepicker({
dateFormat: 'mm/dd/yy',
onSelect: function(startDate) {
...
}
});
});
The screenshot above shows, even I am initializing the input with a short date like 03/15/2018
, the datepicker
won't pick up the format initially. All selections afterward would work as expected.
The fix is you have to set the dateFormat
option manually after the datepicker
initialization:
$(function() {
// $('#date-start').datepicker({
// dateFormat: 'mm/dd/yy',
// onSelect: function(startDate) {
// ...
// }
// });
// $('#date-start').datepicker('option', 'dateFormat', 'mm/dd/yy');
// Or you can chain them
$('#date-start').datepicker({
dateFormat: 'mm/dd/yy',
onSelect: function(startDate) {
...
}
}).datepicker('option', 'dateFormat', 'mm/dd/yy');
});
Try just format option not dateFormat
$('#datepicker').datepicker({
format: 'dd-mm-yyyy'
});
Thats the default, meaning it does not recognise your option.
try:
dateFormat: 'dd-mm-yy'
(small letters)
See this Jsfiddle link that is working example for me:
http://jsfiddle.net/nEGTv/3/