gpt4 book ai didi

c# - 没有时间部分的日期时间比较?

转载 作者:太空狗 更新时间:2023-10-29 22:03:58 25 4
gpt4 key购买 nike

我写了这段代码。但是我想忽略时间,我只想比较一天。

from s in sayac_okumalari
where s.okuma_tarihi == startDate && s.sayac_id == sayac_id
group s by new { date = new DateTime(((DateTime)s.okuma_tarihi).Year, ((DateTime)s.okuma_tarihi).Month, ((DateTime)s.okuma_tarihi).Day, ((DateTime)s.okuma_tarihi).Hour, 1, 1) } into g
select new
{
okuma_tarihi = g.Key.date,
T1 = g.Sum(x => x.toplam_kullanim_T1),
T2 = g.Sum(x => x.toplam_kullanim_T2),
T3 = g.Sum(x => x.toplam_kullanim_T3)
};

例如:

25.02.1987 == 25.02.1987

最佳答案

使用 s.okuma_tarihi.Value.Date == startDate.Date。这应该允许您只比较日期组件。

更新 从评论中的讨论看来用户正在使用 NullableType。因此更新了 NullableType 的解决方案。

关于c# - 没有时间部分的日期时间比较?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11625554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com