Range picker with presets

Build complex pickers to show within popups to make things easy for your users. A great example is date-range selection with presets. If you've ever used Google Analytics, you have probably seen the date range selector for filtering the data, which is very similar to what you can see in this example. Select custom start and end dates along with presets is helpful for easy access to predefined ranges that people are usually interested in.

Would like to explore more date & time picker functionality?  Check out the range examples we have for you →
Download and try example

Demo

Loading the live demo

Preview in full screen

Code

mobiscroll.setOptions({
  locale:  ,
  theme: ' ',
  themeVariant: ' '
});

var formatDate = mobiscroll.formatDate;
var startDate = '2026-10-23T00:00';
var endDate = '2026-10-29T00:00';
var dateInput = document.getElementById('date-filtering');
var startInput = document.getElementById('date-filtering-start');
var endInput = document.getElementById('date-filtering-end');

var now = new Date();
var day = now.getDay();
var monday = now.getDate() - day + (day === 0 ? -6 : 1);

var select = mobiscroll.select('#date-filtering-select', {
  inputElement: document.getElementById('date-select-input'),
  responsive: {
    xsmall: {
      touchUi: true,
    },
    small: {
      touchUi: false,
    },
  },
  onChange: function (args) {
    var selected = args.value;

    if (selected === 'custom') {
      disableInputs(false);
    } else {
      disableInputs(true);

      switch (selected) {
        case 'today':
          calendar.setVal(['2026-10-23T00:00', '2026-10-23T00:00']);
          break;
        case 'yesterday':
          calendar.setVal(['2026-10-22T00:00', '2026-10-22T00:00']);
          break;
        case 'last-week':
          calendar.setVal([
            new Date(now.getFullYear(), now.getMonth(), monday - 7),
            new Date(now.getFullYear(), now.getMonth(), monday - 1),
          ]);
          break;
        case 'last-month':
          calendar.setVal(['2026-09-01T00:00', '2026-09-30T00:00']);
          break;
        case 'last-7-days':
          calendar.setVal(['2026-10-17T00:00', '2026-10-23T00:00']);
          break;
        case 'last-30-days':
          calendar.setVal(['2026-09-24T00:00', '2026-10-23T00:00']);
          break;
      }
    }
  },
});

function disableInputs(disable) {
  var startInst = mobiscroll.getInst(startInput);
  var endInst = mobiscroll.getInst(endInput);

  startInst.setOptions({ disabled: disable });
  endInst.setOptions({ disabled: disable });
}

var calendar = mobiscroll.datepicker('#date-filtering-calendar', {
  controls: ['calendar'],
  select: 'range',
  display: 'inline',
  showRangeLabels: false,
  pages: 'auto',
  startInput: '#date-filtering-start',
  endInput: '#date-filtering-end',
  returnFormat: 'iso8601',
  showOnClick: false,
  showOnFocus: false,
  onInit: function (event, inst) {
    inst.setVal([startDate, endDate]);
    setInputValue(startDate, endDate, inst.s.dateFormat);
  },
  onChange: function () {
    disableInputs(false);
    select.setVal('custom');
  },
});

var popup = mobiscroll.popup('#date-filtering-popup', {
  responsive: {
    xsmall: {
      display: 'bottom',
      touchUi: true,
      buttons: [
        {
          text: 'Apply',
          handler: function () {
            var date = calendar.getVal();

            setInputValue(date[0], date[1] || date[0], calendar.s.dateFormat);
            popup.close();
          },
        },
        'cancel',
      ],
    },
    custom: {
      breakpoint: 559,
      buttons: [],
      display: 'anchored',
      anchor: dateInput,
      anchorAlign: 'start',
      touchUi: false,
      scrollLock: false,
      showArrow: false,
      maxWidth: 920,
    },
  },
});

function setInputValue(start, end, dateFormat) {
  dateInput.value = formatDate(dateFormat, new Date(start)) + ' - ' + formatDate(dateFormat, new Date(end));
}

dateInput.addEventListener('click', function () {
  popup.open();
});

document.addEventListener('click', function (e) {
  if (e.target && e.target.classList.contains('apply-button')) {
    var date = calendar.getVal();

    setInputValue(date[0], date[1] || date[0], calendar.s.dateFormat);
    popup.close();
  } else if (e.target && e.target.classList.contains('cancel-button')) {
    popup.close();
  }
});
  

Duplicate Session

You have signed in on a different machine. To keep everything in sync, you have been signed out of this session.

If you need to invite team members, manage seats and accounts you can do it from the licenses page.

Duplicate Session

We noticed you are logged in on a different machine and have closed your old session.

If you need to invite team members, manage seats and accounts you can do it from the licenses page.