create or replace function ymd( p_year int, p_month int, p_day int) returns date language plpgsql as $$ declare ret_ymd date; begin SELECT TO_DATE(p_year::varchar||LPAD(p_month::varchar, 2, '0')||p_day::varchar,'YYYYMMDD') into ret_ymd; return ret_ymd; end;$$