Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable datepicker past date & time

I'm using datepicker and i like people not be able to select date and time previous to the present day. I used "minDate: 0" to disable the past date but is there a way to disable past time. For example, if the current time is 5am, i do not want people to select 3 or 4 am of the same day.

This is my code:

var dt;
dt = 
$('#datetimepicker3').datetimepicker({
    inline:true,
    minDate: 0,
    format:'m/d/Y H:i',
    formatDate:'d/m/Y'
});
like image 294
user2672112 Avatar asked Aug 10 '15 04:08

user2672112


People also ask

How do I turn off previous date in calendar?

In the Flutter date range picker, you can enable or disable the past dates by using the enablePastDates property of the calendar. When setting the enablePastDates property value as false, you can't able to select the past dates.

How do I disable DatePicker?

To disable a datepicker in jQuery UI we will be using disable() method which is discussed below: jQuery UI disable() method is used to disable the datepicker. Parameters: This method does not accept any parameters.

How do I turn off previous dates in react calendar?

To disable the past and future dates, we have to use the isValidDate property of the react-datetime.

How do I restrict future dates in DatePicker?

if we want to change the date format form yyyy-mm-dd to dd-mm-yyyy than we just simply update on format parameter. after applying this parameter we can easily disable future dates in our datepicker of web form.


1 Answers

Declare dateToday variable and use Date() function to set it. Then use that variable to assign to minDate which is parameter of datepicker.

var dateToday = new Date(); 
$(function() {
    $( "#datetimepicker3" ).datepicker({
        numberOfMonths: 3,
        showButtonPanel: true,
        minDate: dateToday
    });
});
like image 175
madhu Avatar answered Oct 15 '22 21:10

madhu