1SELECT (date_trunc('month', '2017-01-05'::date) + interval '1 month' - interval '1 day')::date
2AS end_of_month;
3
1create function end_of_month(date)
2returns date as
3$$
4select (date_trunc('month', $1) + interval '1 month' - interval '1 day')::date;
5$$ language 'sql'
6immutable strict;
7