<html>
<head>
<script lang="Javascript">
function validateExpDate(){
var expdate ="24-10-2018";
var fields = expdate.split('-');
var date = parseInt(fields[0]);
var month = parseInt(fields[1]);
var year = parseInt(fields[2]);
var today = new Date();
var dd = parseInt(today.getDate());
var mm = parseInt(today.getMonth()+1); //January is 0!
var yyyy = parseInt(today.getFullYear());
if(year >= yyyy){
if(month >= mm){
if(date > dd){
alert('Valid Expiry Date');
}
}
}else{
alert('Invalid Expiry Date Entered!');
}
}
</script>
</head>
<body onload="validateExpDate();">
</body>
</html>
I want to compare the date in variable expdate with current date and display appropriate message. Can anyone figure out the problem and make it work?
console.log(year, yyyy, month, mm, date, dd)before yourifto see the values you'd be comparing. You can also use the debugger to look at them and step through the execution to see what, if anything, is wrong.month >= mmordate > ddfails, then where does the code go?