1

I am trying to get datepicker to allow me to pick dates before year 100.

I have found that the shortYearCutoff option needs to be disabled to have this function properly, as it will always change a date ranging from 00-99 to either 1900-99 or 2000-2099.

I want to be able to pick between years 1-99 - I would really like to go back years before that, but I think I'm going to create another solution for those dates.

Anyway, can anyone think of how this might be done easily, without changing too much?

I found that it seems the javascript Date function changes the 'xx dates to 19xx.

If I can disable that somehow, I should be able to get this working.

Here's my current code

        $("#event_date").datepicker({ minDate: new Date(1, 0, 1),changeYear:true,  maxDate: new Date(4000, 11, 31) , yearRange: '1:4000'});
        $("#event_date").datepicker("option", "dateFormat", "yy-mm-dd");

The datepicker shows the proper years in the drop down, but it always defaults to 19xx when I select anything between 0-100

I also tested this...

        testDate = new Date(12, 11, 11);
        alert(testDate);

This obviously outputs the following:

Dec 11 1912 00:00:00 GMT-0500 (Eastern Standard Time)

Any idea how to get either of these to automatically default to showing the years between 0 and 100?

If I can get Date() to do it, I should be fine with the jquery ui stuff. I don't need this automatic functionality for dates anywhere in the application I am building.

Thank you kindly for your time.

Andrew Whitaker
  • 124,656
  • 32
  • 289
  • 307
adprocas
  • 1,863
  • 1
  • 14
  • 31

1 Answers1

1

You can write the date as a string in the ISO-8601 (publication) format, pass this as the argument to new Date

new Date('0000-01-01T00:00:00.000Z'); // Sat Jan 01 0 00:00:00 GMT+0000 (GMT Standard Time)
       // YYYY-MM-DD hh:mm:ss
Paul S.
  • 64,864
  • 9
  • 122
  • 138
  • Although I didn't end up using this method exactly (I'm not even using datepicker for this anymore), this for sure got me to my resolution and can be resolved using this. If you wanted to edit this further go ahead, but I'll consider it answered. – adprocas Dec 05 '13 at 12:18
  • working fine in other browser but not working in IE 8. – Rakesh Jena Apr 16 '15 at 09:30
  • Found a solution in (http://stackoverflow.com/questions/17592717/result-of-tojson-on-a-date-is-different-between-ie8-and-ie9) – Rakesh Jena Apr 16 '15 at 10:04
  • This solution actually resolve to: Fri Dec 31 -1 16:00:00 GMT-0800 in my chrome browser. – digiwand Sep 08 '16 at 22:49
  • @Ariella yes, that is the same time `Dec 31 16:00:00 + 08:00:00 = 24:00:00 = Jan 01 00:00:00`. The `Z` denotes the timezone of `0` – Paul S. Sep 09 '16 at 23:32
  • @PaulS. Got it. Thanks for the clarification! – digiwand Sep 11 '16 at 05:23