longbill / jquery-date-range-picker

A jQuery plugin that allows user to select a date range
MIT License
1.12k stars 579 forks source link

How to get the selected range? #235

Open deepika1203 opened 8 years ago

deepika1203 commented 8 years ago

Is there any way to get the selected pre-defined range?

For example, if the user selects 'Last 7 days', I need to get some appropriate value so that I could process it.

ankurk91 commented 8 years ago

Take a look at: http://longbill.github.io/jquery-date-range-picker/demo.js

$('#date-range0').dateRangePicker({})
        .bind('datepicker-change', function (event, obj) {
            /* This event will be triggered when second date is selected */
            console.log('change', obj);
            // obj will be something like this:
            // {
            //      date1: (Date object of the earlier date),
            //      date2: (Date object of the later date),
            //      value: "2013-06-05 to 2013-06-07"
            // }
        });

Hope this helps.