I've been using this very handy method of extracting the date portion from a datetime
value:
select dateadd(day, datediff(day, 0, @inDate), 0)
This basically zeroes out the time portion of the date. It's fast, and more importantly it's deterministic - you can use this expression in a persisted computed column, indexed view, etc.
However I'm struggling to come up with something that works with the datetime2
type. The problem being that SQL Server does not permission conversions from integers to the datetime2
type.
Is there an equivalent, deterministic method of stripping the time portion from a datetime2
?