/    Sign up×
Community /Pin to ProfileBookmark

date picker minimum date

Hello,
I’m looking for a solution in order to set the minimal date in the date picker to one year from current day.

`<input type=”date” id=”date” min=**”-1 one year from now”** class=”input” name=”xy” required>`

Thank you very much for your help.
Regards

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumJul 28.2021 — This can be done by this javascript:
``<i>
</i> &lt;input type="date"&gt;
&lt;script&gt;
// get current date:
const dt = new Date();
// subtract 1 from current year:
dt.setFullYear(dt.getFullYear() - 1);
// get ISO date string:
const dateStr = dt.toISOString().substr(0, 10);
// set attribute "min" to that string:
document.querySelector('input[type="date"]').min = dateStr;
&lt;/script&gt;<i>
</i>
``
Copy linkTweet thisAlerts:
@zeropointsevenauthorJul 28.2021 — Hello,

ok thank you very much! That works perfectly.

If I want to add a max date to the same datepicker, can I just add the same code without -1 and .max?
Copy linkTweet thisAlerts:
@SempervivumJul 28.2021 — @zeropointseven#1634814 Yes, give it a try. You can add an amount of months or days in a similar way.
×

Success!

Help @zeropointseven spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...