Find the last day of the Month in PostgreSQL
Check the last day of the current month in PostgreSQL
postgres=# SELECT (DATE_TRUNC('MONTH', ('20230401')::DATE) + INTERVAL '1 MONTH - 1 day')::DATE;
date
------------
2023-04-30
(1 row)
Check the last date of the current date in PostgreSQL
postgres=# SELECT (DATE_TRUNC('MONTH', (now())::DATE) + INTERVAL '1 MONTH - 1 day')::DATE;
date
------------
2023-04-30
(1 row)
Check the last day of next month
postgres=# SELECT (DATE_TRUNC('MONTH', (now())::DATE) + INTERVAL '2 MONTH - 1 day')::DATE;
date
------------
2023-05-31
(1 row)