Setting year in date picker according to current year
datepicker, jquery
Solution
Year range needs to be a string, also you will have to set the max and min dates
$(function () {
var start = new Date();
start.setFullYear(start.getFullYear() - 70);
var end = new Date();
end.setFullYear(end.getFullYear() - 18);
$('#dob').datepicker({
changeMonth: true,
changeYear: true,
minDate: start,
maxDate: end,
yearRange: start.getFullYear() + ':' + end.getFullYear()
});
});
Demo: Fiddle
Problem
I want to limit the starting year of datepicker to 70 years back of current year and end year to 18 years back of current year. The code I tried is as shown below: ``` $(function() { var endyear=new Date().getFullYear()-18; var startyear=new Date().getFullYear()-70; $('#dob').datepick({ changeMonth: true, changeYear: true, yearRange: endyear:startyear }); }); ``` But this is not working. How can I set the start and end date as calculated, in jquery datapicker. Also I want to start the month from the current month and all past dates of current day in the datepicker should be disabled. ie, if current date in datepicker is 05/02/1996, then the dates 01 to 04 should be disabled. I am doing this for restricting users from selecting a date which is invalid for age (ie for those who selects a dob 18years below). How can I achieve this?