<pre>
void Main()
{
var items = new List<TotalPaymentStatistics>()
{
new TotalPaymentStatistics(){RegisteredAt = new DateTime(2021,1,1),TotalAmount = 120},
new TotalPaymentStatistics(){RegisteredAt = new DateTime(2021,1,2),TotalAmount = 120},
new TotalPaymentStatistics(){RegisteredAt = new DateTime(2021,1,3),TotalAmount = 120},
new TotalPaymentStatistics(){RegisteredAt = new DateTime(2021,1,4),TotalAmount = 120},
new TotalPaymentStatistics(){RegisteredAt = new DateTime(2021,1,5),TotalAmount = 120},
new TotalPaymentStatistics(){RegisteredAt = new DateTime(2021,1,6),TotalAmount = 120},
new TotalPaymentStatistics(){RegisteredAt = new DateTime(2021,1,7),TotalAmount = 120},
new TotalPaymentStatistics(){RegisteredAt = new DateTime(2021,1,8),TotalAmount = 120},
new TotalPaymentStatistics(){RegisteredAt = new DateTime(2021,1,9),TotalAmount = 120},
new TotalPaymentStatistics(){RegisteredAt = new DateTime(2021,1,10),TotalAmount = 120},
};
DateTime day0 = items[0].RegisteredAt.AddDays(-1);
var q = items
.GroupBy(x => ((int)((x.RegisteredAt.Subtract(day0).TotalDays-1) / 5)))
.Select(x => new {
x.Key,
Date = day0.AddDays(x.Key*5+1),
Amount = x.Sum(y => y.TotalAmount)
});
foreach(var item in q)
{
Console.WriteLine($"{item.Date.ToString("yyyy-MM-dd")} {item.Amount}");
}
}
// Define other methods and classes here
public class TotalPaymentStatistics
{
public DateTime RegisteredAt { get; set; }
public double TotalAmount { get; set; }
}
</pre>
which will give you :
2021-01-01 600
2021-01-06 600