Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
Advertisement
Comments
-
- -- To use this function
- select eta(current_date, '1976-07-04') as age
Add Comment
Please, Sign In to add comment
Advertisement