Input Type Date Disable Future Date
In this tutorial, we have given three examples of disabling future dates in the input type date by using JavaScript, React.js, and Vue.js. We achieve this by setting the max attribute dynamically using JavaScript, React.js, and Vue.js, which will disable future dates from being selected by the user.
Thanks for your feedback!
Your contributions will help us to improve service.
Example 1: How to Disable Future Date in datepicker using Javascript?
In this example, we use JavaScript to disable future dates in a datepicker element. By using:
const today = new Date().toISOString().split("T")[0];
datePicker.setAttribute("max", today);
It sets today as the maximum date for the datepicker by updating the "max" attribute, thus disabling any future dates in the datepicker
Output of Javascript Disable Future Date in Datepicker
Example 2: React Datepicker Disable Future Dates
In this second example of this tutorial, we use React.js input type date to disable future dates in a datepicker element by setting the max attribute to today's date.
Output of React Js Disable Future Date in Datepicker
Example 3 : Vue Datepicker Disable future dates
In this third example, we use Vue.js to disable future dates in a datepicker element by setting the max attribute to today's date. This will disable future dates in the input type date.