Reputation: 489
All:
Here are the jquery versions that I'm using:
In my ASPX web page, I have the following:
Start Date: <input type="text" id="startdate" size="30"/>
End Date: <input type="text" id="enddate" size="30"/>
<script type="text/javascript">
$(document).ready(function () {
$("#startdate").datepicker({ dateFormat: 'yyyy-mm-dd' });
$("#enddate").datepicker({ dateFormat: 'yyyy-mm-dd' });
});
</script>
However, the startdate and enddate still goes back to the standard format of mm/dd/yyyy default format.
Why does the format fail to change when the dateFormat is specified? Also, how could I fix the problem?
Upvotes: 0
Views: 108
Reputation: 622
try using like this:
$( ".selector" ).datepicker( "option", "dateFormat", "yy-mm-dd" );
Upvotes: 1
Reputation: 489
Thanks @matt-Murdock
Your suggestion worked.
$("#startdate").datepicker({
format: 'yyyy-mm-dd', autoclose: true
});
$("#enddate").datepicker({
format: 'yyyy-mm-dd', autoclose: true
});
However, I'm still confused as to why specifying the way I did in the Original Post failed to work. Almost all the other similar questions on the internet stated that the way I posted it in my Original Post worked. Is it because of the jquery versions that I'm using?
1.jquery 2.1.4
2.jquery-UI 1.11.2
Upvotes: 1
Reputation: 101
You need to change the dateformat in your datepicker.jquery.js than only it will replicate to your view.
Upvotes: 1
Reputation: 719
Try following, your format is not correct.
$( "#startdate" ).datepicker({
dateFormat: "yy-mm-dd"
});
Upvotes: 1
Reputation: 4216
For jquery datepicker, year format should be either y (2 digit) or yy ( 4 digit). So, you may try "yy-mm-dd" for your purpose.
See details here: http://api.jqueryui.com/datepicker/#utility-formatDate
Upvotes: 1