How to disable future dates in daterangepicker
Asked Answered
B

3

11

I am using this plugin for selecting date range, The configuration is my js is as follows:

// date range picker
$('.date_input').daterangepicker({
    autoUpdateInput: false,
    locale: {
        cancelLabel: 'Clear',
        format: 'DD-MM-YY'
    }
});

I need to disable the future dates, i tried using maxDate, but it did not work. Please help me to resolve this issue.Help would be much appreciated Thanks!!

Bathyscaphe answered 10/5, 2016 at 12:36 Comment(3)
What are you trying to achieve, exactly, and what have you done? What does "did not work" mean?Fallen
I was trying to disable/ restrict the user to select the future dates (that is dates after today should not be selectable), so I user maxDate property, but since I was writing this maxDate property in locale {} property, so that maxDate was not working, later I saw that its a seperate property and not to be included in locale {}.Bathyscaphe
Details like this should be in the body of the question. Just edit the question and out them in.Fallen
D
24

You can use maxDate options

(Date object, moment object or string) The latest date a user may select

$('.date_input').daterangepicker({
    maxDate: new Date()
})
Diclinous answered 10/5, 2016 at 12:38 Comment(0)
C
3

Actually setting "0" to maxDate will disable ALL dates not just the future ones. To disable all future days from NOW on, the right way is:

$('.date_input').daterangepicker({
    maxDate: moment()
})
Chromatid answered 28/6, 2019 at 14:47 Comment(1)
Good solution. +1 from me. But remember, this works only if you have moment.js referenced in your project.Fritzie
D
1

Setting "0" to maxDate will disable all future dates

$('.date_input').daterangepicker({
    maxDate: "0"
})
Delirium answered 10/5, 2016 at 12:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.