Question

I am using Datetimepicker & I don't want the user to select past dates, so how I can disable them like jquery ui datepicker do.

Please help

Was it helpful?

Solution

Here's the jquery code you may be looking for:

  $('#datetimepicker').datetimepicker({
    format: 'dd/MM/yyyy hh:mm:ss',
    language: 'pt-BR',
    startDate: new Date()
  });

OTHER TIPS

You need to set min date. set min date as today.

<label for="from">From</label> <input type="text" id="from" name="from"/> <label for="to">to</label> <input type="text" id="to" name="to"/>

var dateToday = new Date();
var dates = $("#from, #to").datepicker({
    defaultDate: "+1w",
    changeMonth: true,
    numberOfMonths: 3,
    minDate: dateToday,
    onSelect: function(selectedDate) {
        var option = this.id == "from" ? "minDate" : "maxDate",
            instance = $(this).data("datepicker"),
            date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
        dates.not(this).datepicker("option", option, date);
    }
});

it works fine: http://jsfiddle.net/nicolapeluchetti/dAyzq/1/

In the portion where you initialize it set the minimum date option

<script type="text/javascript">
      var today = new Date();
      today.setHours(0,0,0,0);
      $('#datetimepicker').datetimepicker({
        format: 'dd/MM/yyyy hh:mm:ss',
        language: 'pt-BR',
        startDate: today
      });
    </script>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top