ashnike
ashnike

Reputation: 11

input date javascript html (min and max)

how to set min date as current date in date picker and max date as 30 days after current date? its for a booking form. I searched everywhere couldn't find any solution.

Upvotes: 0

Views: 83

Answers (2)

KAYZORK
KAYZORK

Reputation: 393

Simply like that:

let input = document.getElementById("input")
input.min = new Date().toISOString().split('T')[0]
input.max = new Date(new Date()+2592000000).toISOString().split('T')[0]
<input type="date" id="input">

Upvotes: 1

Spectric
Spectric

Reputation: 31987

It's as simple as:

const d = new Date();
const min = d.toISOString().split("T")[0]
date.min = min;
var max = d;
max.setDate(d.getDate() + 30)
date.max = max.toISOString().split("T")[0]
<input type="date" id="date">

Upvotes: 3

Related Questions