Reputation: 1
I'm formatting a date with the following code:
$('#test-dp-component .input-group.date').datepicker({
format:'yyyy/mm/dd',
}).datepicker("setDate",'{{ $module->test }}');
So if the date is September 1, 2021, the displayed format is 2021/09/01. However, if I change the format like this:
$('#test-dp-component .input-group.date').datepicker({
format:'mm/dd/yyyy',
}).datepicker("setDate",'{{ $module->test }}');
Then it returns 05/09/1 instead of 09/01/2021. Other formats like mm/yyyy seem to work fine, so why is it freaking out over the mm/dd/yyyy format? Any suggestions?
Upvotes: 0
Views: 103
Reputation: 20901
First, the attribute is dateFormat
, not format
. See the example at Api.jQueryUi.com:
dateFormat
Default: "mm/dd/yy"
The format for parsed and displayed dates. For a full list of the possible formats see the formatDate function.
Second, the year field is indicate with yy
, not with (as you would normally think), yyyy
.
So, you'll want to try:
$('#test-dp-component .input-group.date').datepicker({
dateFormat:'yy/mm/dd',
});
Upvotes: 1