Srini
Srini

Reputation: 883

Last Date of the Month in Postgres Sql

How can we get last day of the month through month name in Postgresql?

Upvotes: 1

Views: 582

Answers (3)

aleroot
aleroot

Reputation: 72636

Try this way :

select date_trunc('month', to_date('January ', 'Month'))+'1month'::interval-'1day'::interval

To parse a date object from a month name you can try this way :

to_date('January', 'Month')

Upvotes: 0

HashSu
HashSu

Reputation: 1517

SELECT (date_trunc('MONTH', now()) + INTERVAL '1 MONTH - 1 day')::date;

Upvotes: 0

starko
starko

Reputation: 1149

SELECT  
    DATE_PART('days', DATE_TRUNC('month', NOW()) 
        + '1 MONTH'::INTERVAL - DATE_TRUNC('month', NOW())
    )

You can use any date instead now

Upvotes: 1

Related Questions