如何在linq查询中从日期截断时间部分? [英] How to truncate time part from date in linq query?
本文介绍了如何在linq查询中从日期截断时间部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写linq查询以从Sql表中获取一些详细信息.我已经创建了列并同时存储了日期和时间.返回时我想省略时间部分.我可以知道这可能吗?
Hi I am trying to write linq query to get some details from Sql table. I have created column and storing date and time both. while returning i want to ommit time part. May I know is this possible?
List<returnObject> obj = new List<returnObject>();
obj = (from c in objectDB.NCT_Project
join user in objectDB.NCT_UserRegistration on c.adminUserId equals user.User_Id
where c.adminUserId == userId
select new returnObject
{
id = c.project_Id,
key = c.key,
created = c.createdDate //currently returns datetime
}).ToList();
任何帮助将不胜感激.谢谢.
Any help would be appreciated. Thank you.
推荐答案
使用根据文档:
当用作LINQ to Entities查询的一部分时,此方法将调用 规范的TruncateTime EDM函数返回给定的日期,并带有 时间部分已清除.
When used as part of a LINQ to Entities query, this method invokes the canonical TruncateTime EDM function to return the given date with the time portion cleared.
这篇关于如何在linq查询中从日期截断时间部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文