Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DateTime comparison without time part?

I wrote this code. But I want to ignore time, I want to compare only day.

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)
};

for example:

25.02.1987 == 25.02.1987
like image 844
AliRıza Adıyahşi Avatar asked Jul 24 '12 06:07

AliRıza Adıyahşi


2 Answers

use s.okuma_tarihi.Value.Date == startDate.Date. This should allow you to compare only the Date component.

Update From the discussion in comments looks like the user is using NullableType. Hence updated the solution for NullableType.

like image 57
Ramesh Avatar answered Sep 30 '22 01:09

Ramesh


Use Date property of DateTime. For ex,

var date= DateTime.Now.Date;
like image 29
L.B Avatar answered Sep 30 '22 03:09

L.B