M
M
McThinker2019-12-26 10:42:54
JavaScript
McThinker, 2019-12-26 10:42:54

How to set the time range date 00:00 - date 23:59 in daterangepicker when selecting a date?

How in daterangepicker, when choosing a date, set the time range date 00:00 - date 23:59?

settings:

$(function() {
    "use strict";

    $('#daterangepicker-custom').daterangepicker({
            startDate: moment().startOf('hour'),
            endDate: moment(),
            minDate: '01/01/2007',
            maxDate: '12/31/2025',
            dateLimit: {
                days: 90
            },
            showDropdowns: true,
            showWeekNumbers: true,
            timePicker: true,
            timePickerIncrement: 1,
            timePicker12Hour: false,
            timePicker24Hour: true,
            ranges: {
                'Сегодня': [moment(), moment()],
                'Вчера': [moment().subtract('days', 1), moment().subtract('days', 1)],
                'За неделю': [moment().subtract('days', 6), moment()],
                'За этот месяц': [moment().startOf('month'), moment().endOf('month')],
                'Прошлый месяц': [moment().subtract('month', 1).startOf('month'), moment().subtract('month', 1).endOf('month')]
            },
            opens: 'center',
            buttonClasses: ['btn btn-default'],
            applyClass: 'small btn-primary',
            cancelClass: 'small btn-danger',
            format: 'DD/MM/YYYY',
            separator: ' to ',

            locale: {
                format: 'DD/MM/YYYY HH:MM',
                applyLabel: 'Принять',
                cancelLabel: 'Отмена',
                fromLabel: 'От',
                toLabel: 'До',
                customRangeLabel: 'Выбрать диапазон',
                daysOfWeek: ['ВС', 'ПН', 'ВТ', 'СР', 'ЧТ', 'ПТ', 'СБ'],
                monthNames: ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'],
                firstDay: 1,

            },
            linkedCalendars: true
        },
        function(start, end) {
            $('#daterangepicker-custom').html(start.format('MMMM D, YYYY,  HH:MM') + ' - ' + end.format('MMMM D, YYYY'));
        }
    );
    $('#daterangepicker-custom span').html(moment().subtract('days', 29).format('MMMM D, YYYY') + ' - ' + moment());
});


clapping:

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
McThinker, 2019-12-26
@McThinker

Figured it out, maybe it will be useful for someone:

startDate: moment({hour:0,minute:0,second:0}).startOf('second'),

ranges: {
                'Сегодня': [moment({hour:0,minute:0,second:0}), moment() ],
                'Вчера': [moment({hour:0,minute:0,second:0}).subtract('days', 1), moment({hour:23,minute:59,second:59}).subtract('days', 1)],
                'За последние 7 дней': [moment({hour:0,minute:0,second:0}).subtract('days', 7), moment({hour:23,minute:59,second:59})],
                'За этот месяц': [moment({hour:0,minute:0,second:0}).startOf('month'), moment({hour:23,minute:59,second:59}).endOf('month')],
                'Прошлый месяц': [moment({hour:0,minute:0,second:0}).subtract('month', 1).startOf('month'), moment({hour:23,minute:59,second:59}).subtract('month', 1).endOf('month')]
            },

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question