how can I filter a collection by smaller time increments?

Given a collection that looks like this:

[ {Price:123.45, DateTime:01/01/18 12:01:10} {Price:89.23, DateTime:01/01/18 12:01:20} {Price:66.13, DateTime:01/01/18 12:01:30} {Price:75.00, DateTime:01/01/18 12:02:45} ] 

How can I filter this collection with linq to only include the first data item which exists closest to the start of each minute? So for example, I want to transform the collection above into the following collection:

[ {Price:123.45, DateTime:01/01/18 12:01:10} {Price:75.00, DateTime:01/01/18 12:02:45} ] 

Also, how can I implement a similar solution but instead of filtering the collection to include the first data item closest to the start of each minute, I want to include the first data item closest to the start of each 5 minute interval? For example, the closest data item to 12:00, 12:05, 12:10, etc?

submitted by /u/random503
[link] [comments]

Leave a Reply