Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EOMONTH equivalent in Postgresql

Tags:

sql

postgresql

Is there a EOMONTH() equivalent in Postgresql? If not, how do I select only the last day of the month for any given month and any given year given a time stamp? For example, I have a dataset with timestamps. From those times, I want to select only 2015-01-31, 2015-02-28, ... 2016-02-29, 2016-03-31, etc. What is an efficient way to do that?

like image 537
Daniel Lee Avatar asked Sep 08 '26 08:09

Daniel Lee


1 Answers

One method is:

select date_trunc('month', col) + interval '1 month' - interval '1 day'
like image 51
Gordon Linoff Avatar answered Sep 11 '26 11:09

Gordon Linoff