Using Linq to Retrieve Date Data

I have a list of <item> of the following

public class Item { public string Link { get; set; } public string Title { get; set; } public string Content { get; set; } public DateTime PublishDate { get; set; } public FeedType FeedType { get; set; } public Item() { Link = ""; Title = ""; Content = ""; PublishDate = DateTime.Today; FeedType = FeedType.RSS; } } 

This is just a parsed RSS feed, now I want to be able to request a list of <item> pull items only using PublishDate today?

However, I'm a little lost ... Can someone shed some light, please?

+4
source share
3 answers

If I understand correctly, the goal here is to remove the comparison time.

Extension Method Syntax>

 var today = DateTime.Today; items.Where( item => item.PublishDate.Date == today ); 

Query syntax

 var today = DateTime.Today; from item in items where item.PublishDate.Date == Today select item 
+9
source
 DateTime today = DateTime.Today; var todayItems = list.Where(item => item.PublishDate.Date == today); 
+4
source
 List<Item> itemList = ...; ListItem<Item> filtered items = itemList.Where(it => it.PublishDate >= DateTime.Today).ToList() 
0
source

All Articles