473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problem converting interval to seconds

Hello !

It is late night and I cannot think right anymore. Please help me to
convert a interval like '2 days 00:22:10.2905' in seconds.

Thank you very much in advance,
Liviu

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #1
1 7117
Liviu BURCUSEL <li***@voxline.ro> wrote:

Hello !

It is late night and I cannot think right anymore. Please help me to
convert a interval like '2 days 00:22:10.2905' in seconds.


http://www.postgresql.org/docs/7.4/s...-datetime.html is
your friend:

epoch

For date and timestamp values, the number of seconds since
1970-01-01 00:00:00-00 (can be negative); for interval values,
the total number of seconds in the interval

SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-08');
Result: 982384720

SELECT EXTRACT(EPOCH FROM INTERVAL '5 days 3 hours');
Result: 442800

And sure enough:

select extract(epoch from interval '2 days 00:22:10.2905');
date_part
-------------
174130.2905
(1 row)

Verifying...

$ bc -l
(2*24*60*60)+(22*60)+10+0.2905
174130.2905

If you want just the seconds:

select floor(extract(epoch from interval '2 days 00:22:10.5905'));
floor
--------
174130
(1 row)

I used a slightly higher decimal part to illustrate the
difference between "::int" and "floor()," since both would
produce the same output for decimal parts < 0.5.

If you want just the seconds, but rounded, rather than truncated:

select extract(epoch from interval '2 days 00:22:10.5905')::int;
date_part
-----------
174131
(1 row)

HTH,
Jim

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #2

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

Similar topics

2
by: Marcus | last post by:
I am having some problems with trying to perform calculations on time fields. Say I have a start time and an end time, 1:00:00 and 2:30:00 (on a 24 hour scale, not 12). I want to find the...
1
by: angrybaldguy | last post by:
Salve. I have an application in which I would like to convert a number of seconds into an INTERVAL DAY TO SECOND value and, later, back to a number of seconds. For reasons relating to...
8
by: Fabio Papa | last post by:
I am trying to write a windows service that sends emails to clients at specific times based on information in a sql db. Since this is done for multiple cities, I start a thread for each city and...
4
by: Andrew Poulos | last post by:
How do I convert a length of time, measured in seconds, into a "point in time" type time interval or what's represented as: time (second,10,2) The format is: PS]] where: y: The number of...
13
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,...
6
by: Denis Zaitsev | last post by:
How can I calculate the number of second in some interval? Neither the secods part, nor the seconds after midnight... Just the full quantity of the seconds. I haven't find any function. ...
17
by: joebenjamin | last post by:
This is a problem I was trying to help a few friends figure out for fun. I am not sure how to go about this, but there is something I am missing here. Here is what we want the output to be: Need...
6
by: alexs | last post by:
hi, I'm moving a mysql database over to using db2 V9.5 The database is used by our radius server to store network accounting information from our switches. One parameter is the length of a...
2
by: Johnny Jörgensen | last post by:
I've got a process I want to run in a thread separate from my main application thread, so I've used a backgroundworker component, and in frmMain.Load I invoke the code using...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.