简体   繁体   中英

How to set a minimum date range limit for the Date Range Picker

I am using the Date Range Picker from daterangepicker.com. How can I set a minimum date range limit for this Date Range Picker? For example, I want to set minimum limit of 3 days so the user can only select a date range of 3 days or more.

At the moment my code for the date range picker is just simply instantiating it with:

$('input[name="daterange"]').daterangepicker();

This is the answer from the developer of the Date Range Picker:

"There is not an option for that, you have to code it yourself"

https://github.com/dangrossman/bootstrap-daterangepicker/issues/1282

Here's one option that seems to work. Note that it doesn't block out dates or give any notification to the user, it just forces the date range to be a certain length (if user selects shorter, it changes the end date to the minimum length based on start date & min length)

https://github.com/dangrossman/daterangepicker/pull/1731/files

The following code works if the minimum date is today. You can also set your minimum date by providing it upon initialization

 $('input[name="view_date"]').daterangepicker({
     singleDatePicker: true,  
     minDate:new Date(), //sets minimum date to today                  
 });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM