I am using the daterangepicker JQuery plugin as I have to pull some date ranges as part of a form. On the same form however, I also want to be able to automatically display the current date and time, preferably through the plugin.
I cant seem to find a way to make this possible as DRP doesn't seem to like the "YYYY/MM/DD HH:mm" format and instead only displays today's date as of midnight (eg. 2017/01/20 00:00), but never the actual time.
How can I fix this?
$(function() {
$('input[name="incident_date"]').daterangepicker({
singleDatePicker: true,
showDropdowns: true,
timePicker: true,
timePicker24Hour: true,
timePickerIncrement: 10,
autoUpdateInput: true,
locale: {
format: 'YYYY/MM/DD HH:mm',
},
});
You should pass the option startDate: new Date().
$('input[name="incident_date"]').daterangepicker({
singleDatePicker: true,
startDate: new Date(),
showDropdowns: true,
timePicker: true,
timePicker24Hour: true,
timePickerIncrement: 10,
autoUpdateInput: true,
locale: {
format: 'YYYY/MM/DD HH:mm'
},
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-daterangepicker/2.1.25/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-daterangepicker/2.1.25/daterangepicker.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-daterangepicker/2.1.25/daterangepicker.css" rel="stylesheet"/>
<input type="text" name='incident_date' />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With