views:

29

answers:

1

H

I need to customize two datepickers.

First shold have:

  • minDate: last ten days of this month (or if easier: 20th of this month)
  • maxDate: 10th of next month

I can only set then as given in "manual" like this: +1m +2w +5d. But that is not good in my case since I do not need to go relative to current data.

Any idea?

I have tried this with no luck:

// temp vars used below
var currentTime = new Date()

// DATEPICKER CURENT MONTH - all fields with class: datepicker_current_month
$(".datepicker_current_month").datepicker({
    dateFormat: 'dd.mm.yy',
    // minDate: '+10d',
    minDate: new Date(currentTime.getYear(), currentTime.getMonth(), 20),
    maxDate: '+3w'
});

BR. Anders

UPDATE - Solution I used the answer from undertakeror and it works just fine. Thnaks for the answer :-)

// temp vars used below
var currentTime = new Date();
var startDateFrom = new Date(currentTime.getFullYear(), currentTime.getMonth() +1, -10); // 10 days before next month
var startDateTo = new Date(currentTime.getFullYear(), currentTime.getMonth() +1, -1); // one day before next month
var endDateFrom = new Date(currentTime.getFullYear(), currentTime.getMonth() +1, 3); // 3rd of next month
var endDateTo = new Date(currentTime.getFullYear(), currentTime.getMonth() +1, 10); // 10th of next month

// DATEPICKER CURENT MONTH - all fields with class: datepicker_current_month
$(".datepicker_current_month").datepicker({
    dateFormat: 'dd.mm.yy',
    minDate: startDateFrom,
    maxDate: startDateTo
});
+1  A: 

This is a nice plugin and has a lot of configuration options http://plugins.jquery.com/project/datepicker . You can find the documentation here http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/documentation.html and some demos here http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/

that being said, i don't know if it is easier to use then the one you tried, but the idea is that you still have to compute the days yourself, something like http://jsfiddle.net/m2HPr/2/

Hope it helps

undertakeror
Thanks, perfekt. From your example I can see that I was close. I should have used getFullYear() and not getYear(). I ended up building it like yours, first the date variables, then insert the variables into the datepicker configuration. Now it works as intended. Thanks again
Tillebeck