The Vertica Forum recently got a makeover! Let us know what you think by filling out this short, anonymous survey.

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.


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.

Can't find what you're looking for? Search the Vertica Documentation, Knowledge Base, or Blog for more information.