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.
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.
VulpesPosted Dec 30, 2013, 7:04 AM
ikrami samiPosted Dec 30, 2013, 8:02 AM
i think the best solution for me Vuples answer it is good thanks al
Dhirendra MisraPosted Dec 30, 2013, 5:36 AM
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 samiPosted Dec 30, 2013, 5:29 AM
Jaganathan BantheswaranPosted Dec 30, 2013, 5:18 AM
Can you post the time xml string?
sha ikPosted Dec 30, 2013, 5:07 AM
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;
}
ikrami samiPosted Dec 30, 2013, 4:09 AM
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 = ???
Jaganathan BantheswaranPosted Dec 30, 2013, 4:00 AM
ikrami samiPosted Dec 30, 2013, 3:09 AM
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 BantheswaranPosted Dec 30, 2013, 12:23 AM