jquery ui datepicker showing wrong date

jquery ui datepicker showing wrong date

montoyammontoyam Posts: 568Questions: 136Answers: 5

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

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    If you use datetime instead date, then you can set the options for the format - see displayFormat and wireFormat. This will give you more control over it.

    Colin

  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    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.

  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    actually, I just realized I can do the same with datatables datepicker...

        .editor-datetime-calendar {
            display: none;
        }
    
  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    No, I take that back. I can't use the DataTable datepicker, it doesn't work the same.

  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    so why doesn't the editor like:
    dateFormat: 'm/yy',

    but is fine with
    dateFormat: 'm/d/yy',

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    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

This discussion has been closed.