I have a start date/time and end date/time field on a form, using type="datetime-local"
I’d like the End Date/Time MIN value to be set to the start Date/Time value.
I can set the min date value with the following script, but the time portion does not work. Looking at the page code once the first value is set, I do see the full value being set (For example: min="2024-11-13T18:55"). However, the date picker is not limiting the time.
let fDate = document.querySelector('#start');
let tDate = document.querySelector('#end');
fDate.addEventListener('change', function() {
tDate.min = this.value;
});
$(document).ready(function(){
$('.first').keyup(function(){
var a = $(this).val();
$('.second').attr('min',a);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<form>
<label>Start Date</label><br>
<input type="datetime-local" class="" name="startDate" id="start" value="">
<br>
<label>End Date</label><br>
<input type="datetime-local" class="" name="issueDate" id="end" value="">
</form>
2
Answers
that’s the way it is:
native date picker does not limit the time.
You can use form validation (with
required
) to detect this error:You may also use a custom date picker (search on gitHub).
Details are commented in example.