Calendar date rolling back to 1930's

Calendar date rolling back to 1930's

I am using a custom Jquery code for Jquery Calendar date picker. For some reason when a date is a and user user want to edit it, the date now shows 1930's. Say I first picked 10 Dec 2028, when I come back to pick it to edit, it now show 10 Dec 1928. Below is my code. Any help will be appreciated.

  1. var format = 'd M y'; // Jquery 'd M y' must match .net 'd MMM yy' date format

  2. function clear_form_elements(ele) {
  3.     $(ele).find(':input').each(function () {
  4.         switch (this.type) {
  5.             case 'datetime':
  6.             case 'text': 
  7.                 $(this).val("");
  8.                 break;
  9.             case 'radio':
  10.                 this.checked = false;

  11.                 $('#dtSubmit').datepicker('setDate', null);
  12.                 $('#dtFinalSubmit').datepicker('setDate', null);
  13.         }
  14.     });
  15. }

  16. $(document).ready(function () {
  17. $('.cDatePicker').off("calendarLoad");
  18. $('.cDatePicker').on("calendarLoad", function () {
  19. var locale = 'en-US';
  20. $.datepicker.setDefaults($.datepicker.regional[locale]);

  21. $(this).datepicker({
  22. dateFormat: format,
  23. changeYear: true,
  24. changeMonth: true,
  25. defaultDate: 0 // Default calender to the current system date.
  26. });

  27. var initDate = $(this).val();
  28. var initSet = initDate != '';
  29. if (initSet) {
  30. var parsedDate = $.datepicker.parseDate(format, initDate);
  31. $(this).datepicker("setDate", parsedDate);
  32. $(this).datepicker("option", "defaultDate", parsedDate);
  33. }

  34. var minAttr = $(this).data('min');
  35. var minSet = typeof minAttr !== typeof undefined && minAttr !== false;
  36. if (minSet) {
  37. var minDateVal = new Date(minAttr);
  38. $(this).datepicker("option", "minDate", minDateVal);
  39. if (initSet == false) {
  40. $(this).datepicker("option", "defaultDate", minDateVal);
  41. }
  42. }

  43. var maxAttr = $(this).data('max');
  44. var maxSet = typeof maxAttr !== typeof undefined && maxAttr !== false;
  45. if (maxSet) {
  46. var maxDateVal = new Date(maxAttr);
  47. $(this).datepicker("option", "maxDate", maxDateVal);
  48. if (initSet == false && minSet == false) {
  49. $(this).datepicker("option", "defaultDate", maxDateVal);
  50. }
  51. }
  52. });
  53. $('.cDatePicker').trigger("calendarLoad");
  54. });

  55. // Override the date validation that to match date format.
  56. $(function () {
  57. $.validator.addMethod('date',
  58.     function (value, element) {
  59.     if (this.optional(element)) {
  60.     return true;
  61.     }
  62.     var valid = true;
  63.     try {
  64.     $.datepicker.parseDate(format, value);
  65.     }
  66.     catch (err) {
  67.     valid = false;
  68.     }
  69.     return valid;
  70.     });
  71. $('.cDatePicker').datepicker({ dateFormat: format });
  72. });