Advertisement
cldscchttn

Redshift/postgres, calculate the interval in years between two days. (age function)

Jan 30th, 2023 (edited)
1,196
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. create function eta(date, date)
  2.   returns int
  3. stable
  4. as $$
  5.   select
  6.     case when $1>=$2 then
  7.     case
  8.       when ( add_months($1 , date_diff('year', $2, $1 ) * (-12) ) ) < $2
  9.       then date_diff('year', $2, $1 ) - 1
  10.       else date_diff('year', $2, $1 )
  11.     end
  12.   else null
  13.   end::int
  14. $$ language sql;
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement