Are LEAST() and ABS() really necessary?
Stew Ashton, July 18, 2016 - 11:22 am UTC
No matter what date you start with, you either subtract a positive number from the later date or subtract a negative number from the earlier date.
alter session set nls_date_format='YYYY-MM-DD HH24:MI';
with t as (
select date '2016-07-01' d1, date '2016-07-18' d2
from dual
)
select d1 - (d1 - d2) / 2 result1,
d2 - (d2 - d1) / 2 result2
from t;
RESULT1 RESULT2
---------------- ----------------
2016-07-09 12:00 2016-07-09 12:00
July 18, 2016 - 12:28 pm UTC
Good point, thanks Stew.
Chris
Why not use AVG()
David Grimberg, July 25, 2016 - 4:07 pm UTC
with dts(dt) as (
select date '2015-09-01' from dual union all
select date '2015-12-07' from dual
)
select to_date(1,'j') + avg(dt-to_date(1,'j'))
from dts;
This will work for any number of dates, not just two.