I have two Input Fields like these,
<div class="form-group mb-3">
<label for="">Challenge Start Date and Time</label>
<input type="datetime-local" class="form-control form-control-sm" name="date" id = "date" value=""/>
</div>
<div class="form-group mb-3">
<label for="">Challenge End Date and Time</label>
<input type="datetime-local" class="form-control form-control-sm" name="end_date" id = "end_date" value=""/>
</div>
What I want to do actually is whatever time the user sets in the "Start" Input, that time + 45 minutes should be set to the 2nd Input Field.
So, I tried the following, but unfortunately, due to the conversion of the Input Time into the String, I am unable to call getMinutes() + 45
var now = new Date();
now.setMinutes(now.getMinutes() - now.getTimezoneOffset());
document.getElementById('date').value = now.toISOString().slice(0,16);
now.setMinutes(now.getMinutes() + 45);
document.getElementById('end_date').value = now.toISOString().slice(0,16);
document.getElementById('date').addEventListener('change', (e) => {
const value = e.target.value;
value.setMinutes(value.getMinutes() + 45);
document.getElementById('end_date').value = now.toISOString().slice(0,16);
});
I get this error whenever I change the value of the First Input Field,
Uncaught TypeError: value.getMinutes is not a function
Can anyone please provide an solution to this problem?
.value
of the field is a string, not a Date instance.