I would like to come to a code that show is a certain date is still valid and for how long.
The code I've come up with so far can check if the date is not in the future. But I'm unable to how if the date is still valid or not. Can someone help me?
function TheorieFunction() {
var startDate = new Date(document.getElementById('DateTheorie').value);
var today = new Date();
if (startDate.getTime() > today.getTime()) {
alert("Error: Given date is in the future");
}
if (startDate.getTime() > today.get(Calendar.YEAR) - 3) {
document.getElementById("Theorietxt").innerHTML = "Your theorie is still valid for" + today.getTime() - startDate.getTime()
"days";
} else {
document.getElementById("Theorietxt").innerHTML = "Your theorie is invalid";
}
}
Date theorie exam: <input type="date" id="DateTheorie" value="2017-01-01">
<span class="validity"></span>
<button id=Btntheorie onclick="TheorieFunction()">Check</button>
<p id="Theorietxt"></p>