Click here to Skip to main content
16,012,168 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
dear one,

One Doubt for asp.net applications,

"System datetime and entering datetime from user(textBox)."

How to Compare These Two date Time in asp.net c#.

i. System.DateTime="2011-12-02 16:01:52.000";
ii. UserDateaTime="2010-12-02 16:01:52.000";



Condition: if Textbox date is not exceeds for System datetime)
1. Condition True, Message Through "Ur Date is past or today.";

2. Otherwise Message Through "Ur date time is Future Date."


Error: Operator '<' cannot be applied to operands of type 'System.Web.UI.WebControls.Label

give me solution.

By mohan
Posted
Updated 25-Nov-11 23:50pm
v3

protected void Button1_Click(object sender, EventArgs e)
{
DateTime dt1 = DateTime.Now.Date;
DateTime dt2 = Convert.ToDateTime(TextBox1.Text.Trim()).Date;

if (dt1 >= dt2)
{
Label1.Text = "present/Past date";
}
else
{
Label1.Text = "Future date";
}
}
 
Share this answer
 
C#
protected void Button1_Click(object sender, EventArgs e)
    {
        string dt1 = DateTime.Now.ToString("MM/dd/yyyy");
        string dt2 = TextBox1.Text;
        if (dt1 == dt2)
        {
            TextBox1.Text = "Correct";
        }
        else TextBox1.Text = "Wrong";
    }



try it..and advice your end MM/dd/yyyy formate ..
 
Share this answer
 
You can use the DateTime.Compare method or compare validator of ajax validation. Or convert it to Int64 by removing the ":" or "/" then compare the values.

Best regards,
Eduard
 
Share this answer
 
Wihout looking out your code, I can guess their is a significant problem in your code.

Because you mentioned -
Quote:
System Current date time and user input date time.

And error is -
Error: Operator '<' cannot be applied to operands of type 'System.Web.UI.WebControls.Label

System.Web.UI.WebControls.Label is not a input control.

You may use CompareValidator to validate input Date entered in TextBox against Systems Current Date.

http://forums.asp.net/t/1116715.aspx/1
 
Share this answer
 
Try
DateTime.Compare Method[^] which will Compares two instances of DateTime and returns an integer that indicates whether the first instance is earlier than, the same as, or later than the second instance.
or try
http://forums.asp.net/t/1025431.aspx/1[^]
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900