470,647 Members | 1,126 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,647 developers. It's quick & easy.

convert interval info into days

Howdy:

Running PostgreSQL 7.2.1 on RedHat Linux 7.2.

How can I convert data in a table that has been created
with the INTERVAL data type into a numeric format?

Say, I have a table with this type of data:

[snip]
-1 years | 00:00
00:00 | 1 year 90 days
00:00 | 1 year 90 days
00:00 | 1 year 90 days
00:00 | 1 year 90 days
00:00 | 1 year 90 days
00:00 | 1 year 90 days
1 year | 2 years
42 days | 2 years
42 days | 2 years
-1 years | 00:00
-1 years | 00:00
-1 years | 00:00
42 days | 2 years
1 year | 2 years
[/snip]

I want to convert all of this into days, but
I don't think I can use 'to_char' because
I get things like this:

[snip example]
test_db=> select to_char('2 years 3 mons 17 days'::interval, 'YY MM DD');
to_char
----------
02 03 17
--

test_db=> select to_char('2 years'::interval)/365;
ERROR: Function 'to_char(interval)' does not exist
Unable to identify a function that satisfies the given argument
types
You may need to add explicit typecasts
[/snip example]

Any suggestions?

Thanks!

-X

Nov 11 '05 #1
0 3787

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Lynn | last post: by
19 posts views Thread by Lauren Quantrell | last post: by
1 post views Thread by Ed Smith | last post: by
reply views Thread by Ian E. Morgan | last post: by
13 posts views Thread by Bruno Wolff III | last post: by
3 posts views Thread by alex.fishman | last post: by
1 post views Thread by Korara | last post: by
reply views Thread by warner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.