It seems like a simple thing to do, but EF doesn't support properties like DateTimeOffset.DateTime
or DateTimeOffset.LocalDateTime
or even DateTime.Date
. I'm trying to filter a DateTimeOffset type field by the DateTime component only (i.e. the 'local' DateTime), which is a simple thing to do in plain sql: where cast(x as datetime) = '2016-12-14'
.
There is a DbFunctions.TruncateTime
, but no corresponding TruncateOffset
.
There just doesn't seem to be any way to cast or convert a DateTimeOffset
object to a normal DateTime
object that works in linq-to-entities. The only conversion is an implicit one from DateTime
to DateTimeOffset
, but not the other way around.
TruncateTime
has two overloadsTruncateTime(Nullable<DateTimeOffset>)
andTruncateTime(Nullable<DateTime>)
– Eldho Dec 14 '16 at 6:41cast(x as datetime)
where x is a DateTimeOffset field. They really need a TruncateOffset function. – Triynko Dec 14 '16 at 15:25