asp.net – 如何使用linq从datetime列获取Date
发布时间:2020-12-16 03:57:49 所属栏目:asp.Net 来源:网络整理
导读:我在数据库中有一列作为EffectiveDate 这是DateTime的类型. 我有一个linq查询从表中获取EffectiveDate.但是当我得到我的时候会得到EffectiveDate. 但在我的linq查询中,我只需要Date,我不想要有效时间. 如何编写Linq查询? 谢谢 解决方法 在任何DateTime结构
我在数据库中有一列作为EffectiveDate
这是DateTime的类型. 我有一个linq查询从表中获取EffectiveDate.但是当我得到我的时候会得到EffectiveDate. 但在我的linq查询中,我只需要Date,我不想要有效时间. 如何编写Linq查询? 谢谢 解决方法
在任何DateTime结构上调用Date属性
EffectiveDate.Date; 或者打电话 EffectiveDate.ToShortDateString(); 或者在调用ToString()时使用“d”格式,更多DateTime格式为here. EffectiveDate.ToString("d"); 编写Linq查询可能如下所示: someCollection.Select(i => i.EffectiveDate.ToShortDateString()); 如果EffectiveDate可以为空,您可以尝试: someCollection .Where(i => i.EffectiveDate.HasValue) .Select(i => i.EffectiveDate.Value.ToShortDateString()); DateTime.Date Property
DateTime.ToShortDateString Method
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 具有引导Navbar的MVC – 将所选项目设置为活
- 如何在调用WCF服务之前弹出一个确认对话框?
- asp.net – 将web应用程序的项目编译成dll
- asp.net-mvc – ASP.NET MVC4 CustomErrors DefaultRedirec
- asp.net-mvc-3 – ASP.NET MVC 3控制器路由 – 使家庭控制器
- asp.net-mvc – mvc 4 beginform with route name
- asp.net-mvc – FileContentResult和国际字符
- asp.net – Response.Redirect和线程被中止错误?
- asp.net – 如何在web.config中读取会话状态信息
- asp.net-mvc – 在MVC 3中跨请求保持查询字符串
推荐文章
站长推荐
- 奇怪的#_ = _出现在response.redirect ASP.NET之
- asp.net-mvc – MVC3自定义输出缓存
- asp.net-mvc – 如何将Model字段值传递给javascr
- asp.net – 如何在mvc中使用自定义成员身份添加更
- asp.net-mvc – 在Html.BeginForm()中使用RouteV
- asp.net-mvc-4 – SignalR连接错误
- asp.net-mvc – 使用MVC和ASP.Net Core重写动态U
- asp.net-mvc – 在ASP.NET MVC中保护ViewModel
- asp.net-mvc – ASP.NET MVC检查用户是否属于[x]
- asp.net-mvc – 在存储库之间调用方法 – 存储库
热点阅读