在 C# 中获取没有时间的日期 [英] get date without time in c#

查看:27
本文介绍了在 C# 中获取没有时间的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我想获取包含返回 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.

推荐答案

A 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆