Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

js Daterange Picker time picker showing current time in time range

I want to show time from 00:00 to 23:59 in custom range option for time picker. By default custom range is selected for me. It works with predefined ranges but not with custom range. I couldn’t find any option in docs to set time picker range for custom range time picker. Here is my initialization code.

            var start = {!! isset($_GET['from'])?"moment('".$_GET['from']."')":"moment().startOf('today')"  !!};
            var end = {!! isset($_GET['to'])?"moment('".$_GET['to']."')":"moment().endOf('today')"  !!};

            function cb(s, e) {
                start = s;
                end = e;
                $('#reportrange span').html(start.format('MMM D') + ' - ' + end.format('MMM D'));
            }

               $('#reportrange').daterangepicker({
                timePicker: true,
                timePicker24Hour: true,
                startDate: start,
                endDate: end,
                ranges: {
                    'Today': [moment().startOf('day'), moment().endOf('day')],
                    'Yesterday': [moment().subtract(1, 'days').startOf('day'), moment().subtract(1, 'days').endOf('day')],
                    'Last 7 Days': [moment().subtract(6, 'days').startOf('day'), moment().endOf('day')],
                    'Last 30 Days': [moment().subtract(29, 'days').startOf('day'), moment().endOf('day')],
                    'This Month': [moment().startOf('month').startOf('day'), moment().endOf('month').endOf('day')],
                    'Last Month': [moment().subtract(1, 'month').startOf('month').startOf('day'), moment().subtract(1, 'month').endOf('month').endOf('day')]
                }
            }, cb);

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You just need to change moment startOf from today to day. Currently its not getting date so it selects custom range by default.

You can look in to moment docs

https://momentjs.com/docs/#/manipulating/start-of/

var start = {!! isset($_GET['from'])?"moment('".$_GET['from']."')":"moment().startOf('day')"  !!};
var end = {!! isset($_GET['to'])?"moment('".$_GET['to']."')":"moment().endOf('day')"  !!};
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading