I have this code:
public void SetPublisherDatesNotAvailable(string strPublisher, DateTimelistDatesNotAvailable)
Publisher pPublisher = _PublisherData.PublisherDictionary[strPublisher];
new List<DateTime>(listDatesNotAvailable.Where(d => d >= DateTime.Now)); // Ignore past dates
_PublisherData.PublisherDictionary[strPublisher] = pPublisher;
But it is failing to include any entry with todays date. It seems to be taking into account the TimeStamp too? That would explain it. But I only want to exclude it if it was yesterdays date.
How do I fix this?
As you mentioned in the question, Both
DateTime.Now will take TimeStamp as well, if you wanted to exclude the TimeStamp means you have to use
d.Date and also
DateTime.Today(which will give you today's date without TimeStamp, and are equal to
DateTime.Now.Date So This line
listDatesNotAvailable.Where(d => d >= DateTime.Now) should be like this:
listDatesNotAvailable.Where(d => d.Date >= DateTime.Today)
You can use
DateTime.Now.Date to get the value without the time component, or more precisely, with the time component set to midnight.