Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

<input type="datetime-local" class="form-control col-md-6" name="book" required>
<script>
  var today = new Date().toISOString().split('T')[0];
  document.getElementsByName('book')[0].setAttribute('min', today);
</script>
like image 263
Jigen Otsuki Avatar asked Dec 30 '25 17:12

Jigen Otsuki


2 Answers

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>
like image 75
Mohammad Ali Rony Avatar answered Jan 02 '26 07:01

Mohammad Ali Rony


In Laravel, Try this:

 <label>Select date & time:</label><br>
    <input type="datetime-local" name="start_time" min="{{today()}}" value="2024-05-01T00:00" max="2026-01-01T00:00"><br>
like image 34
jc dlc Avatar answered Jan 02 '26 07:01

jc dlc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!