jquery ui datepicker showing wrong date
jquery ui datepicker showing wrong date
I am wanting to use jquery UI datepicker instead of DataTables because I just want the user to select the month/year. However, when I switch from 'datetime' to 'date' the incorrect date is displayed in the editor if there is an existing value.
I have seen posts like this: https://datatables.net/forums/discussion/47070/datatables-editor-plugin-datetime-format-issue
But I can't figure out how to fix my issue.
{
label: "Effective Date:"
, name: "FundOrgDeptGroup_Header.effectivedate"
, type: 'date'
, def: AsOfCookie
, opts: {
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'm/yy',
onClose: function (dateText, inst) {
$(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1));
}
}
},
If I change dateFormat: 'm/d/yy' it displays the correct date. changing it to 'm/yy' shows 3/2026
in my controller (this is an MVC project) I have tried various getformatters as well, but nothing worked.
Answers
If you use
datetime
insteaddate
, then you can set the options for the format - seedisplayFormat
andwireFormat
. This will give you more control over it.Colin
yes, but that will give me the dataTables datepicker, right? I want to use the jquery UI datepicker in this case as it is more customizable.(I only want the user to select month/year and hide the days.
actually, I just realized I can do the same with datatables datepicker...
No, I take that back. I can't use the DataTable datepicker, it doesn't work the same.
so why doesn't the editor like:
dateFormat: 'm/yy',
but is fine with
dateFormat: 'm/d/yy',
If you want to use the jQuery UI date picker, you need to refer to their documentation for the options they provide (use the
opts
object for the field to pass options through to it).It isn't immediately obvious to me that it has an option to do what you are looking for.
With Editor's date picker, we never expected anyone to pick just the date and month I'm afraid - I think this is the first time it has been brought up, so it hasn't been writing with that in mind.
Regards,
Allan