In Linq to SQL with Entity Framework, how do you compare solely Date without Time in DateTime types?

.net c# database entity-framework linq-to-sql

Question

Is it possible to compare twoDateTime factors inLinq2Sql but to ignore the Time portion.

The software adds a publication date and saves stuff in the database. I need to be able to pull by the date but yet maintain the precise time.

I'd want to contrast12/3/89 12:43:34 and 12/3/89 11:22:12 and make it ignore the time of day so that each of these are treated equally.

I suppose I can set all of the timings to00:00:00 I genuinely do want to know the time of day before comparing, but I also want to be able to compare solely by dates.

I discovered some code that compares the year, month, and day independently and has the same problem. Exists a more effective approach to this?

1
293
10/22/2019 8:03:31 PM

Accepted Answer

use theDate real estate on theDateTime Object...

if(dtOne.Date == dtTwo.Date)
    ....
518
3/25/2009 7:19:21 PM

Popular Answer

You may use: to make a genuine comparison.

dateTime1.Date.CompareTo(dateTime2.Date);


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow