How Old Am I (In Months)?

Posted April 16, 2019 by James Knicely, Vertica Field Chief Technologist

Cupcakes with blue icing and lit birthday candles
You are probably aware that Vertica has a built-in function named AGE_IN_YEARS. It 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'); age_in_years -------------- 17 (1 row) I was curious to know 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. It does not take into account that we are already 4 months into the current year, or 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:

Have fun!