By default if you compare two dates in a LINQ2SQL query, the resulting SQL will be
DATEDIFF(MILLISECOND, .....)
which requires using BIGINT as well and usually some CONVERT calls depending on what you’re doing. As an example, try looking at the SQL output if you write
(DateTime1 - DateTime2).Days
It’s a mess!
I would just like to call DATEDIFF(DAY, ...) for example. Is this possible?
It is possible! It turns out there are a few nice methods located in
System.Data.Linq.SqlClientthat do exactly this.The resulting call to
DATEDIFFwill contain the appropriate first parameter and you can forget about all the calls toCONVERT.