If only one date is passed into the function it will return the number of months between that date and the current system date. This is perfect for the proud parent!
Examples:
Code: Select all
dbadmin=> SELECT CURRENT_DATE() "Today's Date", AGE_IN_MONTHS(TIMESTAMP '2010-11-21') "My Baby's Age (in Months)";
Today's Date | My Baby's Age (in Months)
--------------+---------------------------
2012-02-16 | 14
(1 row)
Code: Select all
dbadmin=> SELECT AGE_IN_MONTHS(TIMESTAMP '2013-01-01', TIMESTAMP '2012-01-01') "One Year";
One Year
----------
12
(1 row)
Code: Select all
dbadmin=> SELECT AGE_IN_MONTHS(TIMESTAMP '2010-12-12', TIMESTAMP '2012-01-01') "Negative Months";
Negative Months
-----------------
-13
(1 row)