Find last day of month in PostgreSQL

Select query to find the last day of month in PostgreSQL

SELECT (DATE_TRUNC('MONTH', ('20210816')::DATE) + INTERVAL '1 MONTH - 1 day')::DATE;

DATE
-------
2021-08-31

Find last day of month from current date


select (date_trunc('month',current_Date)+INTERVAL '1 MONTH - 1 DAY')::DATE;

Date
-----------
2021-08-31

Check Current Date in Postgress

SELECT Current_Date;

Current_date
-------------
2021-08-16

Breakup of above query to make it more clear in understanding:


select (date_trunc('month',current_Date))::DATE;
Date_trunc
----------
2021-08-01

select (date_trunc('month',current_Date));
date_Trunc
---------------
2021-08-01 00:00:00+05:30

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.