In this post, we are going to see how to compare two dates in Java Script.
<html>Output:
<head>
<title>Date Difference</title>
<script>
function CheckDate()
{
varmyForm=document.forms[0];
var date1= myForm.date1;
var date2= myForm.date2;
if(date1.value.length==0)
{
alert("Enter Start Date");
date1.focus();
return false;
}
if(date2.value.length==0)
{
alert("Enter End Date");
date2.focus();
return false;
}
if (date1.value == date2.value){
alert ("Dates are the same");
}
if (date1.value > date2.value)
{
alert ("End Date is less then Start Date");
return false;
}
else
{
return true;
}
}
</script>
</head>
<body bgcolor='yellow'>
<center><h2>Date Validation Demo
<form name="dateDemo">
<table bgcolor='orange'>
<tr><td>Start Date:</td><td><input type="text" name="date1"></td></tr>
<tr><td>End Date:</td><td><input type=text name="date2"></td></tr>
<tr><td></td><td><input type="button" onClick="return CheckDate();" value="checkDate"></td></tr>
</table>
</form>
<br> Created By Ranga Reddy.
</h2></center>
</body>
</html>
0 comments:
Post a Comment