GEORGE SCOTT 619-792-7153
  • HOME
  • Adwords Q&A
  • Work Diary
    • 2020-21 Work
    • 2018-19 Work
    • 2016-17 Work
    • 2013-14 Work
  • WEBSITES
  • HUMOR

Using Bootstrap daterangepicker.com

6/22/2017

 
This is an amazing date range picker for bootstrap templates but it doesn't come with any sample code for posting back to your webpage, the developer assumes everyone is a javascript expert.  

Here is code to display the date range picker and post the information back the page on the querystring. 

<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'));
//alert("A new date range was chosen: " + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD'));
//window.location.href = "/activity.html?start=" + start.format('YYYY-MM-DD') + '&end=' + end.format('YYYY-MM-DD'));
}
$('#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);

$('#reportrange').on('apply.daterangepicker', function (ev, picker) {
//console.log(picker.startDate.format('MM/DD/YYYY'));
//console.log(picker.endDate.format('MM/DD/YYYY'));
window.location = "activity.html?s=" + picker.startDate.format('MM/DD/YYYY') + "&e=" + picker.endDate.format('MM/DD/YYYY')
});
});
</script>


Comments are closed.

    2016-17 Work

    Examples of my new work in 2016 and 2017

    Archives

    January 2018
    December 2017
    November 2017
    October 2017
    July 2017
    June 2017
    May 2017
    April 2017
    March 2017
    February 2017
    January 2017
    December 2016
    November 2016

    Categories

    All

    RSS Feed

San Diego Easy Traffic School | San Diego Small Business Insurance | Traffic School Online | Finish Traffic School Today | Lucky Traffic School
  • HOME
  • Adwords Q&A
  • Work Diary
    • 2020-21 Work
    • 2018-19 Work
    • 2016-17 Work
    • 2013-14 Work
  • WEBSITES
  • HUMOR