DEV Community

Cover image for Set Max date to Today's date
Visakh Vijayan
Visakh Vijayan

Posted on • Edited on

3 2

Set Max date to Today's date

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!

Top comments (1)

Collapse
 
hughsheehy profile image
hughsheehy

I'd tried something similar to that. Didn't work. Then searched around StackOverflow and found all sorts of complicated solutions. Then found this. Still can't get it to work. I must be doing something particularly silly. And wrong. 🤔

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up