Filter objects inside model class by date

Total Post:108

 1078  View(s)
Rate this:

I have a model object called EventListingResponse like this 

public class EventListingResponse
    public List<events> result { get; set; }
    public int totalResults { get; set; }
 public class events
    public string id { get; set; }
    public string name { get; set; }
    public string startDate { get; set; } //smaple date 2014-03-31T12:30:03

And I am storing data in this object like this 

EventListingResponse eventListResponse = rGetAllEventList();//data from another function.

Now I want to filter this list so that I can get a list of events like , -->events from January -->Events from February etc. Can any one point out a good method to accomplish this?

  1. Post:378

    Re: Filter objects inside model class by date

    Hi John, 

    try this:

    var filtered = from item in eventListResponse.result
          where DateTime.Parse(item.startDate) >= DateTime.Parse("your starting date")
      and DateTime.Parse(item.startDate) <= DateTime.Parse("your ending date")
       select item;

      Modified On Apr-05-2018 06:13:29 AM