0

I need to display the next Meeting Date from a table of meeting dates. Once a date passes as current, the next date is supposed to show up. I've searched for similar examples but no luck:

05/21/2019

07/11/2019

08/08/2019

09/12/2019

10/10/2019

11/14/2019

12/12/2019

Here the Linq query I have that fails. It doesn't return anything for example after the 10/10/2019 date because 11/14/2019 is actually more than 1 month.

var LinqResult = (from c in _context.MeetingSchedule
                 where c.MeetingDate.Date >= DateTime.Now.Date && c.MeetingDate.Date <= DateTime.Now.Date.AddMonths(1)
                  select new { c.Location, c.MeetingDate, c.MeetingTime }).ToArray();

if (LinqResult.Any())
{
  //SEND NEXT MEETING DATE BACK VIA VIEWSTATE
}

Also, I am pretty sure something odd is going to happen on the last month of the year after the meeting happens (December). I am trying to show the current next meeting, and have it change to the next meeting after that once the current one is over. Adding a month to 12 will create a month number 13 which is non-existent.

JustJohn
  • 1,362
  • 2
  • 22
  • 44
  • 2
    Sort meeting schedule ascending after filtering out dates that have already happened then just grab the first one. – JohanP Oct 13 '19 at 03:13
  • 2
    You can put `orderby c.MeetingDate.Date` between `where` and `select` – JohanP Oct 13 '19 at 03:36

1 Answers1

1

You can sort meeting schedule ascending after filtering out dates that have already happened then just grab the first one.

var LinqResult = (from c in _context.MeetingSchedule
                  where c.MeetingDate.Date >= DateTime.Now.Date
                  orderby c.MeetingDate.Date
                  select new { c.Location, c.MeetingDate, c.MeetingTime }).ToArray();

if (LinqResult.Any())
{
  //SEND NEXT MEETING DATE BACK VIA VIEWSTATE
}
JohanP
  • 5,252
  • 2
  • 24
  • 34