Linq 选择昨天的日期
我已经了解到:
DateTime yesterday = DateTime.Today.AddDays(-1);
YesterdaysRegistrations = db.tblForumAuthors.Where(c => c.Join_date == yesterday).Count();
肯定有记录具有昨天的加入日期,但这始终返回 0!谁能告诉我我这样做是否正确?
I've got as far as this:
DateTime yesterday = DateTime.Today.AddDays(-1);
YesterdaysRegistrations = db.tblForumAuthors.Where(c => c.Join_date == yesterday).Count();
There definitely records that have the join date of yesterday, but this returns 0 all the time! Can anyone tell me if I'm doing this correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
AddDays
保留小时/分钟/秒组件。您要么必须使用(如果 c.Join_date 只是日期组件):否则,您将比较范围:
AddDays
keeps the Hour/Minute/Second components. You either have to use (if c.Join_date is only the date component):Otherwise, you compare for range:
你不必削减时间,你只需要确保你没有做完全匹配的事情。
试试这个:
You don't have to strip off the time, you just have to make sure you don't do an exact match.
Try this instead: