Click here to Skip to main content
15,795,789 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear sir,

I want to change the format of date in jQuery. I want selected date in yy-mm-dd format and default date format is mm/dd/yy.

My code

XML
<html 
<head>

<title>jQuery Datepicker: Disable past days</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<script type="text/javascript">
$(function() {
var date = new Date();
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();

$('#datepicker').datepicker({
minDate: new Date(currentYear, currentMonth, currentDate)
});

});
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker" /></p>
</body>
</html>



please help me.
Posted
Updated 3-Jun-14 23:17pm
v3

Code


JavaScript
$(document).ready(function () {
    var date = new Date();
    var currentMonth = date.getMonth();
    var currentDate = date.getDate();
    var currentYear = date.getFullYear();

    $('#datepicker').datepicker({
        minDate: new Date(currentYear, currentMonth, currentDate),
        dateFormat: 'yy-mm-dd'
    });
});

Demo


[Demo] DatePicker Date Format as "yy-mm-dd"[^]
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900