Convert date and time to number with float
. The SQL standard defines this as the number of days since 1900, so it should be fairly portable. For instance:
declare @t table (dt datetime) insert @t select '1950-01-01' union all select '1960-01-01' select cast(avg(cast(dt as float)) as datetime) from @t
This result is 1955-01-01
. Example on SE data.
source share