How to Add Date Ranger Picker and Custom Date Picker
Categories - HTML Tags - JavaScript CSS HTML   Maniruzzaman Akash   5 months ago   302   0

How to Add Date Ranger Picker and Custom Date Picker

Date ranger picker is an important part of an UI to generate a nice date picker experience. We'll just share how to add a simple date range picker using HTML, CSS and Bootstrap Date Range Package.

 

Step 1:

Include Date Ranger Picker CSS

<!-- Date Range Style -->
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />

 

Step 2:

Include Date Ranger Picker JS, Jquery and Moment JS

<script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
    

 

Step 3:

Include HTML to view basic date range picker

<h2>Select Date Range</h2>
<div id="reportrange" style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc; width: 100%">
  <i class="fa fa-calendar"></i>&nbsp;
  <span></span> <i class="fa fa-caret-down"></i>
</div>

 

Step 4:

Include Js Part Specifically for date range picker

<script type="text/javascript">
    $(function() {
         var start = moment().subtract(29, 'days');
         var end = moment();
        
         function cb(start, end) {
             $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
         }
        
         $('#reportrange').daterangepicker({
             startDate: start,
             endDate: end,
             ranges: {
                'Today': [moment(), moment()],
                'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                'Last 7 Days': [moment().subtract(6, 'days'), moment()],
                'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                'This Month': [moment().startOf('month'), moment().endOf('month')],
                'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
             }
          }, cb);
       cb(start, end);
    });
</script>

 

 

Live Demo Example with Code Pen Source Code Example - 

 

 

Previous
#5 Laravel Views