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]](https://us.v-cdn.net/6029397/uploads/defaultavatar/nD0LWW9MQTB29.jpg)
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.
Example:
dbadmin=> SELECT last_day('02/28/2018') NOT_A_LEAP_YEAR, last_day('02/28/2020') A_LEAP_YEAR; NOT_A_LEAP_YEAR | 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.
Example:
dbadmin=> SELECT LAST_DAY(ADD_MONTHS('03/28/2020', -1)) STILL_A_LEAP_YEAR; STILL_A_LEAP_YEAR ------------------- 2020-02-29 (1 row)
Have Fun!
0