1

I m using bootstrap datepicker from eonasdan. http://eonasdan.github.io/bootstrap-datetimepicker/

So I was using events from its documentation.

Following is the code

$('#datetimepicker1,#datetimepicker2').datetimepicker({
  defaultDate:new Date(), 
  pickTime: false
});

$("#datetimepicker1").on("dp.change",function (e) {
   $('#datetimepicker2').data("DateTimePicker").setMinDate(e.date);
});
$("#datetimepicker2").on("dp.change",function (e) {
  $('#datetimepicker1').data("DateTimePicker").setMaxDate(e.date); 
});

So i wanted datepicker2 to be one month ahead by getting date of datepicker1

Thanks in advance...

AbhiCool
  • 39
  • 8
  • possible duplicate of [Javascript function to add X months to a date](http://stackoverflow.com/questions/2706125/javascript-function-to-add-x-months-to-a-date) – max Nov 18 '14 at 13:04
  • @AbhiCool, are you trying to set `datetimepicker2`'s current date to a month ahead or are you trying to set the minDate to a month ahead of the current date of `datetimepicker1`? – Eonasdan Jan 27 '15 at 22:37
  • @Eonasdan, setting date of datetimepicker2 one month ahead of datetimepicker1 and if datetimepicker1 is changed,datetimepicker2 be set one month ahead and datetimepicker2 wiil be disabled for selecting dates between date specified in datetimepicker1 and one month ahead of it. – AbhiCool Mar 27 '15 at 11:36

1 Answers1

1

If I understand what you're trying to accomplish, you can add a month to the e.date with moment.

All date are return as moment objects.

$('#datetimepicker1,#datetimepicker2').datetimepicker({
  defaultDate:new Date(), //can also be moment()
  pickTime: false //depreciated in v4 by the way, 
                  //use format: 'L' or format: 'formatstring'
});

$("#datetimepicker1").on("dp.change",function (e) {
   $('#datetimepicker2').data("DateTimePicker").setMinDate(e.date.add(1, 'M'));
});
$("#datetimepicker2").on("dp.change",function (e) {
  $('#datetimepicker1').data("DateTimePicker").setMaxDate(e.date.add(1, 'M')); 
});
Eonasdan
  • 7,563
  • 8
  • 55
  • 82
  • above code works as needed.Thanks a lot. Only last help i.e if I change datetimepicker1, then default value of datetimepicker2 should one month ahead if I change datetimepicker2, then default value of datetimepicker1 should one month before. – AbhiCool Mar 28 '15 at 06:05