JSFiddle - React, Tailwind, and code Playground
by Shawn Wood
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment-with-locales.min.js"></script>
<input type="text" valus="" id="myDate" />
JavaScript
var getEndDate = function() {
var date = new Date();
date.setDate(date.getDate() + 7);
return date.toISOString().split('T')[0];
}
var preventFutureDays = function(date, days) {
var diffDate = moment(date).diff(moment().format('YYYY-MM-DD'))
var theDuration = moment.duration(diffDate);
alert(theDuration.asDays());
if (theDuration < days) {
return true;
} else {
return false;
}
}
window.onload = function() {
preventFutureDays('2021-04-22');
};