Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Set date input field's minimum date to today

I have a line of code shown below.

<input type='date' min='2022-01-01'></input>

Is there a way I can set the minimum date to ‘today’ using JavaScript, such that any date before today’s date won’t be valid?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

document.getElementById("date").min = new Date().toISOString().split("T")[0];
<input id="date" type='date'></input>

Just change max to min.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading