jquery datepicker getdate format
date, datepicker, javascript, jquery
Solution
The DatePicker object has a handy-dandy built-in date formatter, and since it's a utility function, it doesn't even require you to apply a DatePicker to an element.
var date = new Date();
console.log($.datepicker.formatDate("yy-mm-dd", date));
or if you need the date of a DatePicker:
var date = $("#selector").datepicker("getDate");
console.log($.datepicker.formatDate("yy-mm-dd", date));
Problem
I have two problems in this code using jquery datepicker (first is alert the getdate method with time but I need the date only in format(yyyy-mm-dd)) the second problem I need to get the selected date into the textbox but it gives me error ``` <script src="jquery-1.11.1.min.js"></script> <link rel="stylesheet" type="text/css" href="jquery.datepick.css"> <script type="text/javascript" src="jquery.plugin.js"></script> <script type="text/javascript" src="jquery.datepick.js"></script> <script src="jquery.chained.min.js"></script> <script> $(document).ready(function(){ $('#popupDatepicker').datepick({ dateFormat: 'yyyy-mm-dd', onSelect: function(){ var fullDate = $('#popupDatepicker').datepick('getDate'); document.getElementByID('maach_year').value=fullDate; alert (fullDate); } }); }); </script> <form action='".$server['PHP_SELF']."' method='post'> <table> <tr><td>Birth Date:</td><td><input type='date' id='popupDatepicker' size='15' name='birth_day'></td> <td>Retirement Date:</td><td><input type='text' size='15' id='maach_year' name='maach_year' ></td></tr> <input type='submit'/><br> </table> </form> ``` I want also if I can add 65 to years that user select in the birth date, put it in the retirement textbox Thanks in Advance