Get the last day of the month in PostgreSQL

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)
This entry was posted in PostgreSQL on by .
Unknown's avatar

About SandeepSingh

Hi, I am working in IT industry with having more than 15 year of experience, worked as an Oracle DBA with a Company and handling different databases like Oracle, SQL Server , DB2 etc Worked as a Development and Database Administrator.

Leave a Reply