Say, I have two DATETIME2 columns and I need to select dates between the two. Example: 1/1/2012 08:00 and 1/1/2012 09:00 should produce 1/1/2012 08:30.
I’m trying this:
SELECT CAST((CAST(dtOut AS float(53)) +
CAST(dtIn AS float(53))) / 2 AS DATETIME2) FROM t;
But I get an error that explicit conversion from DATETIME2 is not allowed.
Any idea how to do it?
DateDiff will find the difference between two dates.
As an aside, your method would work if the fields were datetime, not datetime2.