在c#中获取没有时间的日期

编程入门 行业动态 更新时间:2024-10-26 09:27:49
本文介绍了在c#中获取没有时间的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-30 12:56:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1395127.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!