Home > DeveloperSection > Forums > Filter objects inside model class by date
john rob

Total Post:108

Posted on    September-29-2014 12:47 AM

 C# C# 

 1 Reply(s)
 594  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?

Sumit Kesarwani

Total Post:378

Posted on    September-29-2014 1:04 AM

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;

Don't want to miss updates? Please click the below button!

Follow MindStick