set min date field to current date 1

set min date field to current date

// Use Javascript
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0 so need to add 1 to make it 1!
var yyyy = today.getFullYear();

today = yyyy+'-'+mm+'-'+dd;
document.getElementById("datefield").setAttribute("min", today);

Here is what the above code is Doing:
1. We create a new date object called today.
2. We get the day, month and year from the date object.
3. We format the day and month to be 2 digits long.
4. We set the minimum date to be today.

Similar Posts