Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery + Daterangepicker - current date and time?

Tags:

jquery

date

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',
        },
});
like image 582
Armitage2k Avatar asked Nov 26 '25 14:11

Armitage2k


1 Answers

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' />
like image 115
fumihwh Avatar answered Nov 28 '25 03:11

fumihwh



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!