calum.org:~#

SELECT get_months('2001-01-01 08:55:10', '2004-03-13 13:41:33');

Tags: sql programming postgres

Added: 2006-02-15T14:02

SELECT get_months('2001-01-01 08:55:10', '2004-03-13 13:41:33');

I wanted a function to calculate the number of calendar months (not just 31 day months) between two dates in PostgreSQL, and it appeared that it doesn't like dividing an interval by another interval. So I have cranked open my copy of PostgreSQL, and written a function in Pl/pgSQLthat does that.
http://files.calum.org/pg-sql-num-months-function.txt

Hope it's useful to someone.

Suggestions, corrections as comments below.

posted by Calum on 2006-02-15T14:02 under

Add a comment

Your IP:
Please enter 2702623 here: