HTML:
<form id="form1" runat="server">
<div>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<th>
Date1
</th>
<th>
Date2
</th>
</tr>
<tr>
<td>
<asp:TextBox ID="txtDate1" runat="server" />
</td>
<td>
<asp:TextBox ID="txtDate2" runat="server" />
</td>
</tr>
</table>
<asp:Button ID="btnCalculateDate" runat="server" OnClick="CalculateDate" Text="Calculate Date" />
</div>
</form>
C#:
protected void CalculateDate(object sender, EventArgs e)
{
string date1Day = this.txtDate1.Text.Remove(2);
string date2Day = this.txtDate2.Text.Remove(2);
string date1Month = this.txtDate1.Text.Substring(3, 2);
string date2Month = this.txtDate2.Text.Substring(3, 2);
string date1Year = this.txtDate1.Text.Substring(6);
string date2Year = this.txtDate2.Text.Substring(6);
DateTime d1 = Convert.ToDateTime(date1Month + "/" + date1Day + "/" + date1Year);
DateTime d2 = Convert.ToDateTime(date2Month + "/" + date2Day + "/" + date2Year);
if (d1 > d2)
{
ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('Date1 is greater')", true);
}
else if (d1 == d2)
{
ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('Both are same')", true);
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('Date2 is greater')", true);
}
}
Thank You.