I need to validate whether the date mentioned should be greater than or equal to the current date. But problem here is if user is giving old date '03/11/0018', by default the year gets considered as 2018(as per the below code). One way which I did is to take the input data and get the year using substring and handle(not mentioned in the below code). Is there any other way to handle this?
<html>
<head>
<script>
function dateCompare() {
var d1 = new Date('03/11/0018');
var d2 = new Date('03/11/2018'); //consider today's date is 03/11/2018
if(d1 < d2){
//validate the input date
document.write("entered date cannot be earlier to the current date");
}
else{
//validation passed
document.write("Ideally 03/11/0018 is earlier than 03/11/2018 & validation should be failed");
}
}
dateCompare();
</script>
</head>
</html>