4

I'm using Bootstrap 3 Datetimepicker and I need to disable all my future dates, I know it has it's own disabledDates function but I tried so many times and it's still not working.

What am I doing wrong?

$('#data_move').datetimepicker({
    language: 'pt-BR',
    disabledDates: [
        moment("22/02/2017")
    ]
});
VincenzoC
  • 30,117
  • 12
  • 90
  • 112
MattDAVM
  • 505
  • 3
  • 6
  • 25
  • http://eonasdan.github.io/bootstrap-datetimepicker/Functions/#minmaxdate – BugHunter Mar 23 '17 at 11:01
  • Maybe it's me but I'm missing the relevance of a link to the functions page with no other context offered. A useful link would have been: http://eonasdan.github.io/bootstrap-datetimepicker/Options/#minmaxdate – Mike Devenney May 02 '19 at 12:31

2 Answers2

23

You should use maxDate option instead of disabledDates.

Here a working example:

$('#data_move').datetimepicker({
  locale: 'pt-br',
  maxDate: moment()
});
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.css" rel="stylesheet"/>

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/locale/pt-br.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>

<div class='input-group date' id='data_move'>
  <input type='text' class="form-control" />
  <span class="input-group-addon">
    <span class="glyphicon glyphicon-calendar"></span>
  </span>
</div>
VincenzoC
  • 30,117
  • 12
  • 90
  • 112
  • Does the snippet work for you? Are you sure that you are using eonasdan datetimepicker? – VincenzoC Mar 23 '17 at 13:59
  • yes, it worked, and I'm using the datetimepicker I mentioned for sure – MattDAVM Mar 23 '17 at 14:19
  • Ok, I fear that you have to watch what are the differences between your environment and the working snippet. It's difficult to give further help with the current information. – VincenzoC Mar 23 '17 at 14:43
  • How to disable only specifics dates in datetimepicker e.g an array of random dates? – Amir Khan May 14 '20 at 15:15
  • @AmirKhan you can use [disabledDates](https://eonasdan.github.io/bootstrap-datetimepicker/Options/#endisableddates) as shown in the original question. – VincenzoC May 14 '20 at 22:19
  • I am using bootstrap4 datepicker in React JS. I have used type="date" for the date of birth and i do not want user to be able to select current or future dates. How can i do so? – Samriddha Bajpai Jun 14 '22 at 06:17
0
 $('#data_move').datetimepicker({               
            maxDate: new Date
        });

Try this it will work.

Sathish
  • 49
  • 3