Here is my code:
$(function () {
$(\"#datepicker\").datepicker({ dateFormat: \'DD-MM-YY\' });
});
And the datetime picker is shown, but
Try this:
$(function() {
$('#datepicker').datepicker({
dateFormat: 'dd/mm/yy',
}).datepicker('option', 'dateFormat', 'dd/mm/yy');
});
It works 100%.
Setting the default format will solve the problem, this solution works for me while all above do not.
$.datepicker.setDefaults({
dateFormat: 'yy-mm-dd'
});
Source: Datepicker: Adding dateFormat is giving an error
Full example:
In jsp:
<div id="datepicker"></div>
In script:
function datepicker() {
$("#datepicker").datepicker({
showButtonPanel: true,
dateFormat: 'yy-mm-dd',
onSelect: function() {
var dateObject = $('#datepicker').datepicker().val();
alert(dateObject);
}
}
);
}
this one works for me
$('#datepicker').datepicker({ format: 'dd-mm-yyyy' });
C#:-
[Column(TypeName = "date")]
[Display(Name = "Date of Birth")]
[Required]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime? DOB { get; set; }
CSHTL:-
@Html.EditorFor(model => model.DOB, new { htmlAttributes = new { @class = "form-control" , @required = "required", @autocomplete="off"} })
$(document).ready(function () {
var validationerror = false;
$('input[type=date]').datepicker({
dateFormat: "yy-mm-dd",
changeMonth: true,
changeYear: true,
yearRange: "-60:+0"
});
$('.datepicker').datepicker({
format: 'dd-mm-yyyy',
autoclose: true
})