How to format date value before setting to a date picker input field?

463 Views Asked by At

Using JQuery, I created a simple date text field with dateFormat: "mmddyy". There is no problem in the way it works. But the corresponding database field is of type DATE and stores the value in "YYYY-MM-DD" format. So, when I read the value from database and set it to the date text field, the date format appears to be "YYYY-MM-DD", but not "mmddyy". So, how can we format that database date value in JQuery before setting it to the date field ?

Thanks!

3

There are 3 best solutions below

0
On

put this code to your datebox

data-options="formatter:myformatter"

and add the function like below

 <script type="text/javascript">
    function myformatter(date){
       var y = date.getYear();
       var m = date.getMonth()+1;
       var d = date.getDate();
       return (m<10?('0'+m):m)+(d<10?('0'+d):d)+y;
    }

 </script>
1
On

Try Jquery Date format plugin to accomplish it.

http://archive.plugins.jquery.com/project/jquery-dateFormat

0
On

If you use jQuery UI, check out this page jqueryui.com/demos/datepicker/#option-altFormat