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)?

Jim_KnicelyJim_Knicely - Select Field - Administrator

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.


My son is turning 18 this year!

dbadmin=> SELECT age_in_years('06/13/2001');
(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;
(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;
(1 row)

Helpful Links:

Have fun!

Sign In or Register to comment.