1

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

Rajesh Vishnani
  • 95
  • 1
  • 2
  • 20

2 Answers2

6

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

krishna
  • 4,069
  • 2
  • 29
  • 56
1

add dateFormat to your datepicker

$('#pdate').datepicker({ 
   minDate: new Date(currentYear, currentMonth, currentDate),  
   dateFormat: 'mm-dd-yy'
});
Rakesh Sharma
  • 13,680
  • 5
  • 37
  • 44
  • 1
    `yy` is enough in year part, as yyyy will result in year two times shown like `15-05-20142014` – krishna May 15 '14 at 12:21