0

I've seen answers that use either, new Date() or moment() to declare minDate and been marked as the answer but in my case neither worked. E.g. How to disable past dates from today in bootstrap datetimepicker?

The code is:

$('.datePicker').datetimepicker({
    //format: "HH:ii P, dd M yyyy",
    //format: 'YYYY-MM-DD',
    //minDate: new Date(),
    //minDate: moment(),
    minuteStep: 1,
    showMeridian: true,
    todayBtn: true
});

Bootstrap v3.3.7 is being used and it looks like:

enter image description here

As you can see the dates prior to the 16th (today) aren't being disabled. Could this be due to my bootstrap version?

VincenzoC
  • 30,117
  • 12
  • 90
  • 112
Jackson Collins
  • 110
  • 2
  • 10
  • Well you have your `minDate` commented out, which probably doesn't help... – Obsidian Age Jan 16 '18 at 01:55
  • Yes sorry I said I have tested both out with either format too. Just putting them there to show you what code I had – Jackson Collins Jan 16 '18 at 01:57
  • 1
    Which datetimepicker are you using? [`minDate`](https://eonasdan.github.io/bootstrap-datetimepicker/Options/#mindate) is for [eonasdan-datetimepicker](https://eonasdan.github.io/bootstrap-datetimepicker/), while [tarruda's datetimepicker](https://github.com/tarruda/bootstrap-datetimepicker) uses [`startDate`](http://tarruda.github.io/bootstrap-datetimepicker/#options). – VincenzoC Jan 16 '18 at 09:01
  • Sorry for the late reply. That was it, thank you very much. If you write an answer i'll accept it as the answer – Jackson Collins Jan 17 '18 at 07:02
  • 1
    @JacksonCollins I've posted my answer, I'm assuming (from screenshot) that you are using tarruda's datetimepicker. My personal advice is to use eonasdan-datetimepicker, since it is more stable and has a richer API. – VincenzoC Jan 17 '18 at 10:42

1 Answers1

3

minDate is for eonasdan-datetimepicker, while tarruda's datetimepicker uses startDate:

Options

These are the default options for initializing the widget:

$.fn.datetimepicker.defaults = {
  startDate: -Infinity,      // set a minimum date
  endDate: Infinity          // set a maximum date
};
VincenzoC
  • 30,117
  • 12
  • 90
  • 112
  • 1
    After 4 hours of googling and looking for a fix, this worked. Thanks, @VincenzoC ! – MARS Mar 02 '21 at 19:57