views:

32

answers:

1

Hello,

I am using the Jquery Datepicker found here. Does anyone know how I can modify this code to allow for past date selecting.

$('#start-date').bind('dpClosed', function(e, selectedDates) {
    var d = selectedDates[0];
    if (d) {
   d = new Date(d);
   $('#end-date').dpSetStartDate(d.addDays(1).asString()).dpSetSelected(d.asString()).val($(this).val());
  }
 });

Adding a

$('.date-picker').dpSetStartDate('01/01/2000');

doesn't work. :(

I would greatly appreciate all help.

Thanks,

Tim

+1  A: 

If you simply want dates in the past to be selectable it is as simple as:

$('.date-picker').datePicker({startDate:'01/01/2000'});

(see http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerPastDate.html )

Note that the startDate you pass in must me in the same format as you have set Date.format to (or dd/mm/yyyy by default).

You can also dynamically allow e.g. dates in the last year like so:

$('.date-picker'.datePicker({startDate: (new Date()).addYears(-1).asString()});
vitch
Hey vitch.Thanks for that. I knew about 'startDate' but forgot I had changed the date format. Changing the date to my format fixed it.Thanks again. Great Answer!Tim
Tim