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..

3
  • Hello, Replace the code line with below var date = new String(yr + '-' + mon + '-' + day); To var date = new Date(yr + '-' + mon + '-' + day); Commented Jan 3, 2020 at 12:04
  • @HiteshGohel but still its not working 8-) Commented Jan 3, 2020 at 12:10
  • See here: stackoverflow.com/questions/3674539/… Commented Jan 3, 2020 at 12:10

2 Answers 2

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>

Sign up to request clarification or add additional context in comments.

1 Comment

Just set input.value = date
1

Tomorrows date is smart created like that:

var tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.