0

When I click the button I want to console.log the date and time that gets inserted in the input, but when I try I only get 'undefined'.

      $('#picker-start').datetimepicker({
        timepicker: true,
        datepicker: true,
        format: 'y-m-d H:i',
        onShow: function(ct) {
          this.setOptions({
            maxDate: $('#picker-end').val() ? $('#picker-end').val() : false
          })
        }
      })
      $('#picker-end').datetimepicker({
        timepicker: true,
        datepicker: true,
        format: 'y-m-d H:i',
        onShow: function(ct) {
          this.setOptions({
            minDate: $('#picker-start').val() ? $('#picker-start').val() : false
          })
        }
      });
    <div class="form-group">
        <label for="">Start Date</label>
        <input type="text" id="picker-start" class="form-control">
        <label for="">Due Date</label>
        <input type="text" id="picker-end" class="form-control">
        <button type="submit" id="btn-time">get date</button>
      </div>
Daniel_Knights
  • 7,940
  • 4
  • 21
  • 49

1 Answers1

0

HTML:

<div class="form-group">
    <label for="">Start Date</label>
    <input type="text" id="picker-start" class="form-control">
    <label for="">Due Date</label>
    <input type="text" id="picker-end" class="form-control">
    <button type="button" id="btn-time">get date</button>
</div>

jQuery:

$('#btn-time').on("click", function() {
    var startDate = $('#picker-start').val()
    var endDate = $('#picker-end').val()

    console.log(startDate+' - '+endDate);
});