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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted Jun 20, 2013, 4:25 AM EDT
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);
}
}
}
pooja thorat16 reputationPosted Jun 20, 2013, 4:35 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jun 20, 2013, 4:37 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jun 20, 2013, 4:56 AM EDT
I've corrected and highlighted it.
pooja thorat16 reputationPosted Jun 20, 2013, 5:29 AM EDT
generate exception
The string was not recognized as a valid DateTime. There is a unknown word starting at index 0.
plz give other way...
Carl Cioffi13 reputationPosted Jun 20, 2013, 7:45 AM EDT
DateTime dt;
bool isValid = DateTime.TryParse(c.Text,out dt);
if ((isValid) && (dt > DateTime.Now))
{
//do something
}
else
{
//this is a bad date
}
pooja thorat16 reputationPosted Jun 20, 2013, 7:58 AM EDT