开发者

linq how to query a specific date's data

I'm using Linq querying today's date. There is one column in my table called VisitTime which is a开发者_如何转开发 Datetime type.

I want to know how to write query statement to search today's data. Can anyone help me on this?

WebStatDataContext dc = new WebStatDataContext(_connString);

var query=
    from v in dc. VisitorInfors
    where v.VisitTime......
    select v


When working with DateTime.Now, you should always store it in a local variable otherwise you can get really nasty bugs from the clock changing between calls:

var now = DateTime.Now;
var query = from v in dc.VisitorInfors
            where v.VisitTime.Date == now.Date
            select v;


Use DateTime.Now :

DateTime currentDate = DateTime.Now;
var query =    
    from v in dc. VisitorInfors    
    where v.VisitTime == currentDate.Date
    select v;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜