I'm looking for a solution in order to set the minimal date in the date picker to one year from current day.
<input type="date" id="date" min=**"-1 one year from now"** class="input" name="xy" required>
Thank you very much for your help.
// get current date:
const dt = new Date();
// subtract 1 from current year:
dt.setFullYear(dt.getFullYear() - 1);
// get ISO date string:
const dateStr = dt.toISOString().substr(0, 10);
// set attribute "min" to that string:
document.querySelector('input[type="date"]').min = dateStr;
ok thank you very much! That works perfectly.
If I want to add a max date to the same datepicker, can I just add the same code without -1 and .max?
zeropointseven Yes, give it a try. You can add an amount of months or days in a similar way.