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

How to disable previous date using HTML5 datetime-local input?

I would simply like to prevent users from entering or disable the previous dates in input datetime-local , is there a way to do this?

Here is what I have done, unfortunately nothing happens on this code:

HTML:

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

<input type="datetime-local" class="form-control col-md-6" name="book" required>

Script:

<script>
var today = new Date().toISOString().split('T')[0];
document.getElementsByName("book")[0].setAttribute('min', today);
</script>

>Solution :

try this

var today = new Date().toISOString().slice(0, 16);

document.getElementsByName("book")[0].min = today;
<input type="datetime-local" class="form-control col-md-6" name="book" required>
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