I have 5 textbox with time :
Textbox1 = 05:04
Textbox2 = 06:26
Textbox3 = 11:42
Textbox4 = 14:38
Textbox5 = 16:57
Textbox6 = 16:57
Textbox6 = 18:15
and need to check the nearest textbox value to time now
Loading
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 Dec 30, 2013, 2:04 AM EST
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Dec 29, 2013, 7:23 PM EST
ikrami sami188 reputationPosted Dec 29, 2013, 10:09 PM EST
Textbox1 = 05:04
Textbox2 = 06:26
Textbox3 = 11:42
Textbox4 = 14:38
Textbox5 = 16:57
Textbox6 = 16:57
Textbox6 = 18:15
and
if my time now is = 10:00 so i need to have code to give me ( Textbox3 ) which has value ( 11:42 ) the closest time to my actual time now
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Dec 29, 2013, 11:00 PM EST
ikrami sami188 reputationPosted Dec 29, 2013, 11:09 PM EST
i have app which caculate prayer times, so i get the actual times through the webservice, 7 times for prayers, so i need to show just the closest prayer time :
foreach (XmlNode node in nodes)
{
string Fajr = node["Fajr"].InnerText;
string Sunrise = node["Sunrise"].InnerText;
string Dhuhr = node["Dhuhr"].InnerText;
string Asr = node["Asr"].InnerText;
string Sunset = node["Sunset"].InnerText;
string Maghrib = node["Maghrib"].InnerText;
string Isha = node["Isha"].InnerText;
// so her i need to just store the closest prayer time and this will be run every 1 min
this.ParyerLabel.Text = ???
sha ik12 reputationPosted Dec 30, 2013, 12:07 AM EST
public TimeSpan FindTime()
{
TimeSpan actualTS;
string currentTime = "14:38";
DateTime[] startDate = new DateTime[]
{
Convert.ToDateTime("16:57"),
Convert.ToDateTime("11:42"),
Convert.ToDateTime("06:26"),
Convert.ToDateTime("14:38"),
Convert.ToDateTime("18:15"),
Convert.ToDateTime("05:04"),
Convert.ToDateTime("16:57")
};
List
lstDT.Sort();
int timeIndex = lstDT.FindIndex(i => i.TimeOfDay == Convert.ToDateTime(currentTime).TimeOfDay);
if (timeIndex != 0)
{
TimeSpan ts1 = lstDT[timeIndex].TimeOfDay - lstDT[timeIndex - 1].TimeOfDay;
TimeSpan ts2 = lstDT[timeIndex + 1].TimeOfDay - lstDT[timeIndex].TimeOfDay;
if (ts1 < ts2)
{
actualTS = ts1;
}
else
{
actualTS = ts2;
}
}
else
{
actualTS = lstDT[timeIndex +1].TimeOfDay;
}
return actualTS;
}
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Dec 30, 2013, 12:18 AM EST
Can you post the time xml string?
ikrami sami188 reputationPosted Dec 30, 2013, 12:29 AM EST
Dhirendra MisraRank #4,173 · 360 reputationPosted Dec 30, 2013, 12:36 AM EST
You can create a function to get close time.
You can call this function by changing the time strings to TimeSpan object like as below:
It is better to split string into arr variable and then use it.
Hope it may be useful.
Thanks
ikrami sami188 reputationPosted Dec 30, 2013, 3:02 AM EST
i think the best solution for me Vuples answer it is good thanks al