I have an IEnumerable<DateTime>
with a number of dates in it. How would I get the earliest date from that collection?
Thanks!
Dave
var earliest = collection.Min();
You can do this immediately with LINQ using Enumerable.Min
.
DateTime minDate = dateCollection.Min();
Since DateTime
implements IComparable<DateTime>
, Enumerable.Min
will use DateTime.CompareTo
to find the minimum DateTime
in the collection.
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