Suppose I have a date
column called hire_date
in the following format YYYY-MM-DD
. I want to truncate the date so that the last day of the month is shown. For example, a record with 2015-01-11
is shown as 2015-01-31
.
I know that I can use DATE_TRUNC('month', hire_date)
to get a timestamp of the beginning of the month but what about the end of the month?
The answer selected here How to get the last day of month in postgres? states to use the last_day()
function but I've tried LAST_DAY(hire_date)
and I get an error saying function last_day(date) does not exist
.
Is there an easier way than the following:
DATE_TRUNC('month', hire_date) + INTERVAL '1 month' - INTERVAL '1 day'