作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何添加日期是where子句。我正在使用以下代码。
var opportunites = from opp in this.DataContext.Opportunities
join org in this.DataContext.Organizations on opp.OrganizationID
equals org.OrgnizationID
select new
{
org.CreatedDate,
org.OrganizationName
};
if (createdDate != string.Empty)
opportunites = opportunites.Where(opp =>
opp.CreatedDate == Convert.ToDateTime(createdDate));
但是使用这段代码我不会返回任何结果。我认为错误在于 == 运算符。
我想我应该有这样的代码
"where createdDate between" + createdDate + "00:00:00" + and createdDate + "23:59:59"
如何在 LINQ 中归档这个东西。
有什么建议吗?
最佳答案
您可以只提取 DateTime 的“日期”部分,如下所示:
opp.CreatedDate.Date == Convert.ToDateTime(createdDate).Date
关于c# - 如何在 WHERE 子句 (LINQ) 中使用 DateTime?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1005154/
我是一名优秀的程序员,十分优秀!