Overview
Date Range Picker can be attached to any webpage element to pop up two calendars for selecting dates, times, or predefined ranges like "Last 30 Days". For full documentation please check the
plugin's site .
Usage
Date Range Picker's CSS and Javascript files are bundled in the global plugin bundles and globally included in all pages:
copy
<link href="assets/plugins/global/plugins.bundle.css" rel="stylesheet" type="text/css"/>
<script src="assets/plugins/global/plugins.bundle.js"></script>
Initialization
Date Range Picker's CSS is highly customized in
sass/vendors/plugins/_daterangepicker.scss
SCSS file in order to use it as native component within the design system. The SCSS code is compiled into
assets/plugins/global/plugins.bundle.css
and globally included in all pages.
Date Range Picker's Javascript is bundled with
assets/plugins/global/plugins.bundle.js
and globally included in all pages.
Basic Examples
Basic example of Date Range Picker attached to an input element:
copy
$("#kt_daterangepicker_1").daterangepicker();
<div class="mb-0">
<label class="form-label">Basic example</label>
<input class="form-control form-control-solid" placeholder="Pick date rage" id="kt_daterangepicker_1"/>
</div>
With Times
Enable date selection with times:
copy
$("#kt_daterangepicker_2").daterangepicker({
timePicker: true,
startDate: moment().startOf("hour"),
endDate: moment().startOf("hour").add(32, "hour"),
locale: {
format: "M/DD hh:mm A"
}
});
<div class="mb-0">
<label class="form-label">Example</label>
<input class="form-control form-control-solid" placeholder="Pick date rage" id="kt_daterangepicker_2"/>
</div>
Single Date Picker
Use Date Range Picker as single date picker:
copy
$("#kt_daterangepicker_3").daterangepicker({
singleDatePicker: true,
showDropdowns: true,
minYear: 1901,
maxYear: parseInt(moment().format("YYYY"),10)
}, function(start, end, label) {
var years = moment().diff(start, "years");
alert("You are " + years + " years old!");
}
);
<div class="mb-0">
<label class="form-label">Example</label>
<input class="form-control form-control-solid" placeholder="Pick date rage" id="kt_daterangepicker_3"/>
</div>
Predefined Date Ranges
Enable date range selection from predefined options:
copy
var start = moment().subtract(29, "days");
var end = moment();
function cb(start, end) {
$("#kt_daterangepicker_4").html(start.format("MMMM D, YYYY") + " - " + end.format("MMMM D, YYYY"));
}
$("#kt_daterangepicker_4").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);
<input class="form-control form-control-solid" placeholder="Pick date rage" id="kt_daterangepicker_4"/>
Modal Example
Use Date Range Picker within Bootstrap Modal:
copy
$("#kt_daterangepicker_5").daterangepicker();
<!--begin::Modal-->
<div class="modal fade" tabindex="-1" id="kt_modal_1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
<!--begin::Close-->
<div class="btn btn-icon btn-sm btn-active-light-primary ms-2" data-bs-dismiss="modal" aria-label="Close">
<span class="svg-icon svg-icon-2x"></span>
</div>
<!--end::Close-->
</div>
<div class="modal-body">
<div class="mb-0">
<label for="" class="form-label">Select date</label>
<input class="form-control form-control-solid" placeholder="Pick date" id="kt_datepicker_10"/>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-light" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
<!--end::Modal-->