0

所以我想要做的是获取数据库中的条目数,这些条目形成一个选定的日期,并且从那天所在的那一周开始。数据库列和我的变量都是日期时间字段。我的日期方法是:

private int multiUse_timesInADay()
    {
           daydate date = currentDate.date;
        var submitCount = from campaignMessages in dcCRData.Mytable
                          where  campaignMessages.Created == date 
                          select campaignMessages;
        int count = submitCount.Count();

        return count;
    }

我对如何进行周搜索有点迷茫。有任何想法吗?

4

1 回答 1

1
//first get to the last monday i.e. start of the week

int delta = DayOfWeek.Monday - currentDate.date.DayOfWeek;
DateTime monday = currentDate.date.AddDays(delta);


var submitCount = from campaignMessages in dcCRData.Mytable
                  where  campaignMessages.Created >= monday &&  campaignMessages.Created <= monday.AddDays(7)    
                  select campaignMessages; 
于 2013-08-16T00:59:23.813 回答