I have a database that stores records, and these records have a date and time. As a request, I built a graph to show how many records were recorded for each hour of the day throughout the year.
So, for this, I just grouped by hours and counted the number of objects in each of these hours:
var lstByHour =
lstAllRecords.Where(x => x.RecordDateTime.Year == year && !x.deleted)
.GroupBy(x => x.RecordDateTime.Hour)
.Select(x => new object[] {x.Count()}).ToArray();
I use this information to enter a line chart, and here is what it looks like:

.. , . , , . .. 0 35.. 1 41.. , , 35 + 41 = 76/2 = 38.. 38 0 1. 2 . .
, , , .. .
.
UPDATE
, , 30- . :
var groups = lstAllRecords.GroupBy(x =>
{
var stamp = x.RecordDateTime;
stamp = stamp.AddMinutes(-(stamp.Minute % 30));
stamp = stamp.AddMilliseconds(-stamp.Millisecond - 1000 * stamp.Second);
return stamp;
})
.Select(g => new object[] {g.Count()})
.ToArray();
6000 , .
2
, , 5- , ..
var grouped = from s in lstAllRecords.Where(x => x.RecordDateTime.Year == year && !x.deleted)
group s by new DateTime(s.RecordDateTime.Year, s.RecordDateTime.Month,
s.RecordDateTime.Day, s.RecordDateTime.Hour, s.RecordDateTime.Minute / 2, 0) into g
select new object[]{ g.Count() };
public partial class DailyRecord
{
public int ID { get; set; }
public System.DateTime RecordDateTime { get; set; }
public string IncidentNumber { get; set; }
public string Summary { get; set; }
public bool deleted { get; set; }
}