10

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!!

Thusila Bandara
  • 285
  • 4
  • 22
Prabhjot Kaur
  • 427
  • 3
  • 6
  • 19
  • What are you trying to achieve, exactly, and what have you done? What does "did not work" mean? –  May 10 '16 at 13:18
  • 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 {}. – Prabhjot Kaur May 11 '16 at 06:48
  • Details like this should be in the body of the question. Just edit the question and out them in. –  May 11 '16 at 12:21

3 Answers3

20

You can use maxDate options

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

$('.date_input').daterangepicker({
    maxDate: new Date()
})
Satpal
  • 132,252
  • 13
  • 159
  • 168
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()
})
  • Good solution. +1 from me. But remember, this works only if you have moment.js referenced in your project. – Rohan Rao Feb 18 '20 at 11:43
1

Setting "0" to maxDate will disable all future dates

$('.date_input').daterangepicker({
    maxDate: "0"
})
Murtaza Khursheed Hussain
  • 15,176
  • 7
  • 58
  • 83