jQuery Datepicker opens on future date

jQuery Datepicker opens on future date

Peter.prc48Peter.prc48 Posts: 22Questions: 6Answers: 1

Hi,
I'm trying to use the jQueryUI Datepicker with a US date format and I find that when I click on an existing date, the datepicker opens at some future date in 2021. When looking at the examples on your site, it would appear its also happening in your own examples: https://editor.datatables.net/examples/dates/jqueryui-formatting.html - select any row and edit it - check the date shown in the editor form.
I'm seeing this in both IE10 and Chrome.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,893Questions: 1Answers: 10,145 Site admin
    Answer ✓

    Thanks for pointing that out - the issue is in the date format used was:

    dateFormat: 'm/d/y'

    It should be:

    dateFormat: 'm/d/yy'
    

    i.e. tell jQuery UI to expect a four digit year.

    I've corrected that on the example you linked to now and it works as it should.

    Regards,
    Allan

  • Peter.prc48Peter.prc48 Posts: 22Questions: 6Answers: 1

    Thanks Allan.
    I was still have issues with this (showing some future date in the jquery datapicker) and I noticed the JSON was still outputting a date with a time offset, even though I had a GetFormatter on the field. It wasn't until I looked through the downloaded code examples and found the 'date' object in the model was a string, whereas in my model it was a DateTime object so I guess it was formatting it properly and then converting it back into a DateTime object before rendering the JSON.
    Sorted now thanks.

This discussion has been closed.