Is there a way to average multiple dates in oracle? avg doesn't do any good.
Thanks.
There are several types of date/time averaging in SQL. You can either average the date/time stamp as a whole, the date part of the date/time stamp, or the time portion of the date/time stamp.
This page provides you with the most commonly used Oracle date functions that help you handle date and time data easily and more effectively. Add a number of months (n) to a date and return the same day which is n of months away. Extract a value of a date time field e.g., YEAR, MONTH, DAY, … from a date time value.
Is there a way to average multiple dates in oracle? avg doesn't do any good. Thanks. Show activity on this post. The definition of an "average date" is subjective, but you could convert your dates to a Julian number, then average those, round it off, then convert back to a date.
Oracle handles some date arithmetic naturally - eg TRUNC (SYSDATE) + 1 will return tomorrow's date. 3) compare the average back to SYSDATE & convert back to date.
The definition of an "average date" is subjective, but you could convert your dates to a Julian number, then average those, round it off, then convert back to a date.
create table dates (dt DATE);
insert into dates
values ('24-APR-2012');
insert into dates
values ('01-JAN-2012');
insert into dates
values ('01-JAN-2013');
insert into dates
values ('25-DEC-1900');
select to_date(round(avg(to_number(to_char(dt, 'J')))),'J')
from dates;
Here's the SQL Fiddle: http://sqlfiddle.com/#!4/98ce9/1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With