I have a class with a DateTimeOffset property:
public class Sample
{
public DateTimeOffset expires { get; set; }
}
and eventually a collection of them:
IEnumerable<Sample> collection;
2 questions:
What is the best way to create a method that returns all the Sample items from the collection where expires is greater than now and is still today (i.e. before midnight)?
What is the best way to return all Sample items from the collection where expires is in the next 24 hours?
// greater than now, still today
collection.Where(d => d.expires.DateTime > DateTime.Now && d.expires.Date == DateTime.Today);
// expires in the next 24 hours
collection.Where(d => d.expires.DateTime > DateTime.Now && d.expires.DateTime < DateTime.Now.AddHours(24));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With