Hi, I'm making a tv guide program and I'm letting the user select a start date and an end date and I need to output all the programmes which fall between those times.

I'm using linq like this to filter the data

var result = from p in programmes
      where p.Start_t.TimeOfDay > Start.TimeOfDay && p.End_t.TimeOfDay < End.TimeOfDay
      select p;

foreach (Programme p in result)
string[] arr = { p.Start_t.TimeOfDay.ToString(), p.End_t.TimeOfDay.ToString(), p.Repeat };

Start and End are the DateTimes which the user has selected


As you can see from the image there are some wrong results and i cant work out what i'm doing wrong, most of the results are correct but there are a couple which are wrong.


It's doing exactly what you told it to do. Notice the problem times cross the midnight boundary. You need to include the actual date (you know, day/month/year) in the comparison, not just the time.

This question has already been answered. Start a new discussion instead.