Reputation: 883
How can we get last day of the month through month name in Postgresql?
Upvotes: 1
Views: 582
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
Reputation: 1517
SELECT (date_trunc('MONTH', now()) + INTERVAL '1 MONTH - 1 day')::date;
Upvotes: 0
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