现在需要按周分组,代码如下,想要获取第几周,也就是周的index,应该怎么写?
var query = from item in dt.AsEnumerable()
group item by new
{
date=Convert.ToDateTime(item.Field<string>(1)).AddDays(-(int)Convert.ToDateTime(item.Field<string>(1)).DayOfWeek+1),
cpdl=item.Field<string>(0)
} into g
select new
{
cpdl=g.Key.cpdl,
date = g.Key.date.ToString("yyyy-MM-dd"),
jysl= g.Sum(n => n.Field<decimal>(2)),
bhgsl= g.Sum(n => n.Field<decimal>(3)),
value = Math.Round(100*(g.Sum(n=>n.Field<decimal>(2)-n.Field<decimal>(3))/g.Sum(n=>n.Field<decimal>(2))),2)
};