Question

I am working with jQuery date picker, and the problem is the format of the date, i want the format same as the MySQL date format as i do not get the correct value of the date in MySQL table, i am pasting the code below.

<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();
$('#pdate').datepicker({
minDate: new Date(currentYear, currentMonth, currentDate)

});
});
</script>

Form

<input type="text" name="date" title="" placeholder="mm / dd / yyyy" class="date" id="pdate"  required="required"/>

Currently the date picker's date format is 05/16/2014 and MySQL's date format is MM-DD-YYYY

Was it helpful?

Solution

do like this

$("#pdate").datepicker({showOn: 'focus',changeMonth: true,
    changeYear: true,dateFormat: 'mm-dd-yy',
    minDate: new Date(currentYear, currentMonth, currentDate)
 });

You need to add dateFormat attribute to your datepicker() function.

for more info check here

OTHER TIPS

add dateFormat to your datepicker

$('#pdate').datepicker({ 
   minDate: new Date(currentYear, currentMonth, currentDate),  
   dateFormat: 'mm-dd-yy'
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top