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!
How Old Am I (In Months)?

You are probably aware that Vertica has a built-in function named AGE_IN_YEARS which returns the difference in years between two dates, expressed as an integer.
Example:
My son is turning 18 this year!
dbadmin=> SELECT age_in_years('06/13/2001'); age_in_years -------------- 17 (1 row)
I was curious how many months he’s been on the planet so I figured that I could just multiply his current age by 12.
dbadmin=> SELECT age_in_years('06/13/2001') * 12 age_in_months; age_in_months --------------- 204 (1 row)
But that’s not completely accurate as it does not take into account that we are already 4 months into the current year and for any past Leap Years. Luckily there is a built-in Vertica function named AGE_IN_MONTHS that does!
dbadmin=> SELECT age_in_months('06/13/2001') actual_age_in_months; actual_age_in_months ---------------------- 214 (1 row)
Helpful Links:
https://www.vertica.com/docs/9.2.x/HTML/Content/Authoring/SQLReferenceManual/Functions/Date-Time/AGE_IN_MONTHS.htm
https://forum.vertica.com/discussion/239587/how-old-am-i
Have fun!
0