score:1

Accepted answer

first modify the class as per @abatischcev

public class prayertime
{
    public timespan fajr { get; set; }
    public timespan sunrise { get; set; }
    public timespan zuhr { get; set; }
}

then modify the linq query select part as:

select new prayertime()
{
    fajr = timespan.parse(c.attribute("fajr").value),
    sunrise = timespan.parse(c.attribute("sunrise").value),
    zuhr = timespan.parse(c.attribute("zuhr").value)
};

then your check should be:

var obj = filtereddata.first();
timespan currenttime = myday.timeofday;
string result = string.empty;
if (currenttime >= obj.fajr && currenttime < obj.sunrise)
{
    result = "fajar";
}
else if (currenttime >= obj.sunrise && currenttime < obj.zuhr)
{
    result = "zuhar";
}
textbox1.text = result;

(by the way, zuhr time should be between zuhr and asar :))

score:0

the problem here is your code is "stringly typed". i would be better to use type that is design for time e.g. datetime, but to quick fix it:

               // don't you need a third one here?
               select new prayertime()
               {
                   fajr = c.attribute("fajr").value,
                   sunrise = c.attribute("sunrise").value,
               };

tu get current hour:

int currenthour = datetime.now.hour;

then is just simple comparison of two integers.

var data = filtereddata.first();
int fajrhour = int.parse(data.fajr.substring(0, 2), cultureinfo.invariantculture);
int sunrisehour = int.parse(data.sunrise.substring(0, 2), cultureinfo.invariantculture);
int zuhrhour = int.parse(data.zuhr.substring(0, 2), cultureinfo.invariantculture);

if(fajrhour <= currenhour && currenhour < sunrisehour)
{
    mytextbox.text = data.fajr; // or to show value fajrhour.tostring()
}
if(sunrisehour <= currenhour && currenhour  < zuhrhour)
{
    mytextbox.text = data.zuhr; //    zuhrhour.tostring()
}
// don't you need a third one here?

score:1

first, keep not string but timespan object:

public timespan fajr { get; set; }
public timespan sunrise { get; set; }

to do this parse xml into datetime:

timespan ts = timespan.parse(c.attribute("attr"));

so:

timespan now = datetime.now.timeofday; // time part only
var data = filtereddata.first();

string result = null;
if (data.fajr <= now && now < data.sunrise); // notice operators greed
    result = data.fajr;
else if (data.sunrise <= now && now <= data.zuhr)
    result = data.zuhr;
mytextbox.text = result;

Related Query

More Query from same tag