How to Add Date Ranger Picker and Custom Date Picker
Categories - HTML Tags - JavaScript CSS HTML   Maniruzzaman Akash   3 years ago   2940   2 minutes   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="" />


Step 2:

Include Date Ranger Picker JS, Jquery and Moment JS

<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></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>


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'));
             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);



Live Demo Example with Code Pen Source Code Example - 



PHP If-else-elseif and Switch-case
PHP String Functions - All necessary String functions in PHP to manage strings better.