Click here to Skip to main content
15,905,229 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want to compare 2 textboxs with date in gridview such a way that one must be less than other.
Posted
Comments
Himanshu Yadav 5-Dec-12 0:44am    
please elaborate yr question

Of course, you could get TextBox.Text string properties, try to parse each into System.DateTime using one of the methods of this structure: Parse, TryParse, ParseExact or TryParseExact; and then you could compare the points in time just using the operators '<', '>', '>=', '=' or '<=': http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^].

But why?

It looks like you tend to use strings representing data instead of data itself, which is a big mistake. Why not having time from whatever data source you have, comparing it, and only them display it as string properties of text boxes or anything else?

Alternatively, you can use some DateTimePicked instead of pretty much irrelevant text boxes. Please see:
http://www.codeproject.com/KB/webforms/DateTimePicker.aspx[^].

—SA
 
Share this answer
 
v2
Comments
Espen Harlinn 5-Dec-12 18:14pm    
Nice reply :-D
Sergey Alexandrovich Kryukov 5-Dec-12 21:56pm    
Thank you, Espen.
--SA
hi dear,

you use textbox. I think dateTimePicker1 is better then textbox compare tow date. if you use dateTimePicker1 then solution is

if (dateTimePicker1.Text > dateTimePicker1.Text)
{
// Continue
}
 
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