age('now',date::datetime)

From: Bob Dusek <bobd(at)palaver(dot)net>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: age('now',date::datetime)
Date: 1998-11-05 12:01:24
Message-ID: 36419394.5AC4FD2C@palaver.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello again,

I am using the age() function to determine the average shelf-life of
inventory items that are being stored in my database. And, I think the
function is definitely worth having around. It is saving me a lot of
time. However (there's always a catch), I think it would be a hundred
times more useful to me if I could, using some sort of Postgres function
or conversion operator, take the output of the age function, which is
returned as type 'timespan' and condense that into just 'days' or
'months'.

In other words, when I do this:

database => select age('now', '09-01-1998'::datetime);

Instead of it telling me this:

age
---------------------------------------
@ 2 mons 4 days 6 hours 40 mins 47 secs

I would like to be able to make it tell me:

age
---------
66.3 days

or something to that effect.

Is there a way I can do this? At first, I tried the date_part function,
but (for obvious reasons) it didn't do what I thought it was doing.

Please let me know,

Bob

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bob Dusek 1998-11-05 12:04:57 Re: [GENERAL] casting float8 type
Previous Message Joe Fisher 1998-11-05 10:30:52 Help with PostgreSQL...