Home Ask Login Register

Developers Planet

Your answer is one click away!

Kamal February 2016

pickaday.js user can select any date from next 15 days only

I'm using pickaday.js. I want the user to only be able to select a date between today and the next 15 dates. I have set current date by using javascript new Date() function but I'm unable to figure out how to set max day to next 15 days only. Please check my code below


<input value="" id="datepicker" type="text" readonly>


 var currentDate = new Date();
        var day = currentDate.getDate();
        var month = currentDate.getMonth() + 1;
        var year = currentDate.getFullYear();

 var picker = new Pikaday(
              field: document.getElementById('datepicker'),
              firstDay: 1,
              format: "DD/MM/YYYY",
              minDate: new Date(year, month, day),
              maxDate: new Date(2020, 12, 31)


Pierre Granger February 2016

I guess you can do it with setDate :

var minDate = new Date(year, month, day) ;
var maxDate = new Date() ;
maxDate.setDate(minDate.getDate()+15) ;

Regarding Subtract days from a date in JavaScript

Sharky February 2016

just set the maxDate like this

maxDate: new Date(currentDate.getTime() + 15 * 24 * 60 * 60 * 1000)

Rich February 2016

var someDate = new Date(); 
someDate.setDate(someDate.getDate() + 15)
var picker = new Pikaday({
  field: document.getElementById('datepicker'),
  firstDay: 1,
  format: "DD/MM/YYYY",
  minDate: new Date(),
  maxDate: someDate 

That will add 15 days to your calendar.

Post Status

Asked in February 2016
Viewed 2,797 times
Voted 10
Answered 3 times


Leave an answer

Quote of the day: live life