Search code examples
codeigniterbootstrap-datetimepicker

I want bootstrap-datetimepicker only Year and Month


enter image description here

Now, Bootstrap datetimepicker viewed YYYY-DD-MM format.
But, I want only YYYY-DD format.

enter image description here

For example, Like the picture above.

Now Source.
Also it did not resolve to remove the DD to the source.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-md-3">
  <div class="col-md-5">
    <label style="margin-top: 8px;margin-left: 33px; white-space:nowrap;">datetimepicker</label>
  </div>
  <div class="col-md-7">
    <input class="form-control" type="text" name="daterange" value='<?php if(isset($_GET['to']) && $_GET['to'] != '') { echo @$_GET['to']." - ".@$_GET['from']; } ?>' />
  </div>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script>
$(function() {
        $('input[name="daterange"]').daterangepicker({
          <?php if(isset($_GET['to']) && $_GET['to'] != '') { ?>startDate:'<?php echo @$_GET['to']; ?>',<?php } ?>
          <?php if(isset($_GET['to']) && $_GET['to'] != '') { ?>endDate:'<?php echo @$_GET['from']; ?>',<?php } ?>
          timePicker: false,
          timePicker24Hour: false,
          format: 'YYYY-MM-DD'
        }, function(start, end)
        {
          location.href = "/Driving/drivingHistoryList?to="+start.format('YYYY-MM-DD')+"&from="+end.format('YYYY-MM-DD')+"<?php echo "&userid=".@$_GET['userid']."&carid=".@$_GET['carid']."&goal=".@$_GET['goal']."&order=".@$_GET['order']."&order_type=".@$_GET['order_type']."&page=".@$_GET['page']."&count=".@$_GET['count']; ?>";
        });
      });
</script>


Solution

  • Set 'viewMode' and 'format'. Try

    $('input[name="daterange"]').datetimepicker({
          <?php if(isset($_GET['to']) && $_GET['to'] != '') { ?>startDate:'<?php echo @$_GET['to']; ?>',<?php } ?>
          <?php if(isset($_GET['to']) && $_GET['to'] != '') { ?>endDate:'<?php echo @$_GET['from']; ?>',<?php } ?>
          viewMode: 'years',
          format: 'MM/YYYY'
    }