The Vertica Forum recently got a makeover! Let us know what you think by filling out this short, anonymous survey.
Please take this survey to help us learn more about how you use third party tools. Your input is greatly appreciated!

What's the last day of the month?

[Deleted User][Deleted User] Administrator
edited February 2018 in Tips from the Team

This tip was authored by Jim Knicely.

The Vertica built-in LAST_DAY function returns the last day of the month for a specified date. This function comes in handy for leap years.


dbadmin=> SELECT last_day('02/28/2018') NOT_A_LEAP_YEAR, 
                 last_day('02/28/2020') A_LEAP_YEAR;
 2018-02-28      | 2020-02-29
(1 row)

In one of my previous positions, an accountant asked how to compute the last day of the previous month. That’s not a problem when you combine a few Vertica built-in functions.


dbadmin=> SELECT LAST_DAY(ADD_MONTHS('03/28/2020', -1)) STILL_A_LEAP_YEAR;
(1 row)

Have Fun!

Sign In or Register to comment.