how to compare current time and my label time ?
i develop one windows form application in that how to compare current time and label time?andi have multiple labels how i compare in loop?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
pooja thoratPosted Jun 20, 2013, 11:58 AM
Carl CioffiPosted Jun 20, 2013, 11:45 AM
DateTime dt;
bool isValid = DateTime.TryParse(c.Text,out dt);
if ((isValid) && (dt > DateTime.Now))
{
//do something
}
else
{
//this is a bad date
}
pooja thoratPosted Jun 20, 2013, 9:29 AM
generate exception
The string was not recognized as a valid DateTime. There is a unknown word starting at index 0.
plz give other way...
VulpesPosted Jun 20, 2013, 8:56 AM
I've corrected and highlighted it.
VulpesPosted Jun 20, 2013, 8:37 AM
pooja thoratPosted Jun 20, 2013, 8:35 AM
VulpesPosted Jun 20, 2013, 8:25 AM
Call it initially with ComareDates(this).
private void CompareDates(Control container)
{
foreach(Control c in container.Controls) // correction
{
if(c is Label)
{
DateTime dt = DateTime.Parse(c.Text);
if (dt > DateTime.Now) // or whatever
{
// do something
}
}
else if(c.HasChildren)
{
CompareDates(c);
}
}
}