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;
精彩评论