-2

How would you change the date result format to be MM-DD-YY rather than MM/DD/YY in my code below?

 <script>
  $( function() {
    $( "#input5" ).datepicker();
  } );
  </script>

I found this but I am not able to make it work with my code although I assume I am just doing something wrong :( How to change date format (MM/DD/YY) to (YYYY-MM-DD) in date picker

Thomas
  • 11
  • 1
  • 6

2 Answers2

0

As per the documentation, you should use this way:

$( function() {
  $( "#datepicker" ).datepicker();
  $( "#datepicker" ).datepicker( "option", "dateFormat", "mm-dd-yy" );
} );
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
0

You can use the Bootstrap Datepicker library and set the format to 'mm-dd-yy' like this format: 'mm-dd-yy'.

<script   src="https://code.jquery.com/jquery-2.2.3.min.js"   integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo="   crossorigin="anonymous"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.0/js/bootstrap-datepicker.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.1/css/bootstrap-datepicker3.min.css">
<script>
$( document ).ready(function() {
    $("#from-datepicker").datepicker({ 
        format: 'mm-dd-yy'
    });
    $("#from-datepicker").on("change", function () {
        var fromdate = $(this).val();
        alert(fromdate);
    });
}); 
</script>
<input type="text" id="from-datepicker"/>
Damien
  • 1,582
  • 1
  • 13
  • 24