您好我正在尝试编写linq查询以从Sql表中获取一些详细信息。我创建了列并存储了日期和时间。回来的时候我想省略时间部分。我可以知道这可能吗?
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();
任何帮助将不胜感激。谢谢。
答案 0 :(得分:10)
created = DbFunctions.TruncateTime(c.createdDate)
根据文件:
当用作LINQ to Entities查询的一部分时,此方法将调用 规范的TruncateTime EDM函数用于返回给定的日期 时间部分清除。
答案 1 :(得分:2)
您需要做的只是在createdDate上调用'Date'属性。
select new returnObject
{
id = c.project_Id,
key = c.key,
created = c.createdDate.Date
}).ToList();
答案 2 :(得分:1)
created = c.createdDate.ToString("HH:mm")
created = c.createdDate.ToString("H:mm")
created = c.createdDate.ToString("hh:mm tt")
created = c.createdDate.ToString("h:mm tt")