Reputation: 356
I have a bootstrap datetimepicker. It's current minimum time is whatever the time is in real time. I need the minimum time to be real time plus 20 minutes added. So if it is 2:30PM I need the minimum time allowed to be 2:50PM in the datetimepicker. How can I do this?
<div class="calender">
<div class='input-group date' id='datetimepicker1'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
@section scripts {
<script>
$("#datetimepicker1").datetimepicker({
minDate: new Date()
});
</script>
}
</div>
Upvotes: 3
Views: 7413
Reputation: 8087
To make it simple, you can use moment.js because it supports a functionality of add()
.
In your case, you can use .add(20,'minutes')
or .add(20, 'm')
.
Reference: https://momentjs.com/docs/#/manipulating/add/
else
var currentDateTime = new Date();
var newDateTime = currentDateTime.setMinutes(currentDateTime.getMinutes() +20);
$('datetimepicker1').val(newDateTime);
Reference: http://jsfiddle.net/MKK2V/
Upvotes: 1
Reputation: 337560
In effect you're asking 'how can I add 20 minutes to the current Date?' To do that you can use setMinutes()
, like this:
var minDate = new Date();
minDate.setMinutes(minDate.getMinutes() + 20);
$("#datetimepicker1").datetimepicker({
minDate: minDate
});
Upvotes: 4