Set Max date to Today's date

Visakh Vijayan - Nov 21 '19 - - Dev Community

Client requested for the maximum date to be selected in the date field will be of today. So we did this -

var today = new Date();

var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0');
var yyyy = today.getFullYear();

today = yyyy + '-' + mm + '-' + dd;

<input max="` + today + `" />
Enter fullscreen mode Exit fullscreen mode

It worked for us!

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .