1

Im using html5 datepicker like [input type="date"],

I just need to increment current date + 1. i mean show the tomorrow date and future dates only, the current date and previous dates wants to go disable state only show the future dates..

anyone please help me..

here is my tried code.

// Disable date

var input = document.getElementById("preDate");
var today = new Date();
var day = today.getDate()+1;
var mon = new String(today.getMonth()+1); //January is 0!
var yr = today.getFullYear();

if (mon.length < 0) {
  mon = "0" + mon;
}

var date = new String(yr + '-' + mon + '-' + day);

input.disabled = false;
input.setAttribute('min', date);
<div class="form-group col-3 rfdate">
  <label class="col-sm-6 control-label p-sm-0">Refund Date</label>
  <input type="date" class="form-control" id="preDate" name="preDate" />
</div>

Fiddle: Code Here..

Joe
  • 558
  • 1
  • 8
  • 30

2 Answers2

1

Try this:

// Disable date

var input = document.getElementById("preDate");
var today = new Date();
var day = today.getDate()+1;
var mon = new String(today.getMonth()+1); //January is 0!
var yr = today.getFullYear();

if (mon.length > 0) {
  mon = `0${mon}`;
}
if (day < 10) {
  day = `0${day}`;
}

var date = `${yr}-${mon}-${day}`;

input.disabled = false;
input.setAttribute('min', date);
input.value = date;
console.log(date);
<div class="form-group col-3 rfdate">
  <label class="col-sm-6 control-label p-sm-0">Refund Date</label>
  <input type="date" class="form-control" id="preDate" name="preDate" />
</div>
Ritesh Khandekar
  • 3,885
  • 3
  • 15
  • 30
1

Tomorrows date is smart created like that:

var tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
jefi
  • 185
  • 1
  • 13