问题描述
限时送ChatGPT账号..当我想获取包含返回 0 行的日期的行时,我的表AbsenteeismDate"(类型=日期)上有一列.
i have a column on my table "AbsenteeismDate" (type=date) when i want to get rows contain a date it return 0 row.
这是我的 C# 代码:
this is my C# code :
DateTime ClassDate = DateTime.Parse(lblDate.Content.ToString());
var Abs = dbs.GETAbsenteeisms.Where(a => a.AbsenteeismDate == ClassDate ).ToList();
我查了一下,有问题:数据库中的AbsenteeismDate"和ClassDate"不相等.
i checked it there is a problem : "AbsenteeismDate" on database and "ClassDate" aren't equal.
例如
AbsenteeismDate=1396-05-31
和
ClassDate=1396-05-31 12:00:00 AM
我怎样才能得到 DateTime 类型的没有时间的日期,因为 AbsenteeismDate 的类型是我数据库中的日期.
how can i get Date without Time with DateTime type because AbsenteeismDate's type is date on my database.
对不起,我的英语不太好.
sorry i can't speak English very well.
推荐答案
DateTime
总是有一个日期和时间部分,但是如果你想获得一个 DateTime
该日期和时间值设置为午夜 12:00:00 (00:00:00) 使用 DateTime.Date
:
A DateTime
always has a date and time portion, but if you want to get a DateTime
of that date and the time value set to 12:00:00 midnight (00:00:00) use DateTime.Date
:
var Abs = dbs.GETAbsenteeisms
.Where(a => a.AbsenteeismDate == ClassDate.Date)
.ToList();
这篇关于在c#中获取没有时间的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论