DEV Community

loading...

Set Max date to Today's date

vjnvisakh profile image Visakh Vijayan ・1 min read

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 + `" />

It worked for us!

Discussion

pic
Editor guide