0

I cannot seem to get the date format 'yyyy/mm/dd' to work in Datepicker - I have tried all the "solutions" out there, and the only thing that has worked for me so far is this. But as you can see, it is a drop-down menu, and I do nor want to choose the format every time - I just want it to be that way.

Now, the linked script does it like this:

<script>
    $(function() {
        $( "#datepicker" ).datepicker();
        $( "#format" ).change(function() {
            $( "#datepicker" ).datepicker( "option", "dateFormat", $( this ).val() );
        });
    });
</script>

Dropdown:

<option value="yy-mm-dd">ISO 8601 - yy-mm-dd</option>

I am not very good with jQuery, so I have absolutly no clue how to "convert".

Albert MN.
  • 713
  • 1
  • 16
  • 33
  • Possible duplicate of [jQuery UI DatePicker - Change Date Format](http://stackoverflow.com/questions/1328025/jquery-ui-datepicker-change-date-format) – Xavjer Dec 03 '15 at 08:41
  • try `yy-MM-dd` as no-caps `mm` means minutes. – Theunis Dec 03 '15 at 08:42

2 Answers2

4
$(function() {
    $("#datepicker").datepicker({ 
            dateFormat: 'yy/mm/dd'
    }); 
});

Will do, you should set it while initializing the datepicker.

void
  • 36,090
  • 8
  • 62
  • 107
0

Your jQuery datepicker should be constructed as seen below. I've added changeMonth and changeYear to give you added functionality but these can be removed if you don't need them. To attach the datepicker to your html, use the input element and set it's id, as shown below.

Remember as well, that you need to include both jQuery references below in order to access the library.

<script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>



<script>
        $(function () {
            $("#datepicker").datepicker({ dateFormat: "yy/mm/dd", changeMonth: true, changeYear: true });
        });
    </script>


<input type="date" id="datepicker" />

Working example Codepen

Scanner
  • 597
  • 1
  • 9
  • 19