473,654 Members | 3,108 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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'::interva l)/365;
ERROR: Function 'to_char(interv al)' 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 3937

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3206
by: Graeme Longman | last post by:
Hi everyone, I was wondering if anyone has written some Python code which uses a start date and end date and a given interval (day, month or year) and outputs all the time periods for that range and interval. For example you may wish to find all the months between the dates '2004-02-14' and '2004-08-04'. You would maybe use a function where you pass in those starting and ending dates and the interval 'month' and you'd get back a list...
4
2998
by: Lynn | last post by:
On a form I have Date_Start Date_End I have a new Date_Start1 Date_End1 which the use inputs. I need to validate that Date_Start1 and Date_End1 are a date range entirely separate from Date_Start and Date_End i.e. no overlapping
19
7271
by: Lauren Quantrell | last post by:
I have a stored procedure using Convert where the exact same Convert string works in the SELECT portion of the procedure but fails in the WHERE portion. The entire SP is listed below. Specifically, I have a problem with this portion in the WHERE clause: DATEADD(Day,tblMyEventTableName.ReminderDays, @DateNow) Between CONVERT(smalldatetime,str(DATEPART(Month, @DateNow)+1) + '/' + str(DATEPART(Day, tblMyEventTableName.TaskDateTime)) + '/'...
10
2255
by: Karsten Hilbert | last post by:
I have the need to output intervals (ages in this case). PostgreSQL takes great care to handle months correctly (eg take into account varying months lengths). This is only possible if either end point or start point of an interval are known. For post processing some of the ambiguity of what "2 mons" means would be removed if "61 days" was returned. Is there a way to tell PostgreSQL to return that type of interval (eg use weeks, days,...
1
1987
by: Ed Smith | last post by:
The Postgres INTERVAL literal is not compliant with the ANSI 2003 SQL Spec. Here's the Postgres way: # select INTERVAL '45 DAY'; interval ---------- 45 days (1 row) The spec. says
0
1810
by: Ian E. Morgan | last post by:
After being frustrated with the inflexible output of intervals, I've written a pl/pgsql function to do what I want, and hopefully some other people might find it useful. Output is a string that matches the output format of an interval as closely as possible, but rather than counting days as a fixed 24-hours, it recalculates days based on the number of hours in the desired 'day'. For example, this is very useful for summing up work time...
13
2847
by: Bruno Wolff III | last post by:
Recently there has been some discussion about attaching a timezone to a timestamp and some other discussion about including a 'day' part in the interval type. These two features impact each other, since if you add a 'day' to a timestamp the result can depend on what timezone the timestamp is supposed to be in. It probably makes more sense to use a timezone associated with the timestamp than say the timezone GUC or the fixed timezone UTC. ...
3
6509
by: alex.fishman | last post by:
Hi, I need to implement a container for integer intervals, something that looks like (1,5), (10,20), (4,7), etc. The container has to be of the following properties: search for an arbitratry interval for intersection in O(log n) or O(1) if possible, insert and delete in O(log n). Does this sound simple? Is there any reference implementation that I can look at?
9
2643
by: archana | last post by:
Hi all, I want to know about interval of timer. I am using timer in windows service.I head somewhere that when i set interval property of timer while setting interval, restart time of Pc is consider. My question is if i am using timer in my windows service, is there any place where interval related information like interval set used by my
0
8290
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8489
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8594
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7307
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.