How to check date from less than and greater than with example
Ex:I have Two Date First One : 01/10/2015 and Second One : 10/10/2015 .
Then I insert Any Middle date like : 02/10/2015 , 05/10/2015 etc... Than Show Me Message That Product Allready
booking . PlZ Answer This Querry
Upendra Pratap ShahiPosted Aug 20, 2015, 3:46 AM
Design Page-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestPage2.aspx.cs" Inherits="TestPage2" %>
DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>title>
head>
<body>
<form id="form1" runat="server">
<div style="text-align: center">
<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>
div>
form>
body>
html>
CodeBehind Page-
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);
}
}
Kindly accept the answer.Viral PatelPosted Aug 20, 2015, 3:41 AM
Vaikesh K PPosted Aug 20, 2015, 3:36 AM
Syntax :
Value Type
Condition
Less than zero
t1 is earlier than t2.
Zero
t1 is the same as t2.
Greater than zero
t1 is later than t2.