Redshift/postgres, calculate the interval in years between two days. (age function)
create function eta(date, date)
returns int
stable
as $$
select
case when $1>=$2 then
case
when ( add_months($1 , date_diff('year', $2, $1 ) * (-12) ) ) < $2
then date_diff('year', $2, $1 ) - 1
else date_diff('year', $2, $1 )
end
else null
end::int
$$ language sql;
Comments
0 B
|0 👍
/0 👎
0 B
|👍
/👎
0 B
|👍
/👎