Solved

Time conversion to Metric

Posted on 2011-03-15
7
423 Views
Last Modified: 2012-05-11
Hello Experts!

I am looking for this Postgres function that will take a "timestamp without time zone" value and convert it to metric time.

for example:
time                             metric time [hh.mm]
19 days 06:17:00      462.28
155:05:00                     155.08
0
Comment
Question by:daniel_spiri
7 Comments
 
LVL 10

Expert Comment

by:borgunit
ID: 35137607
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 35140187
You could extract the epoch (which does second) and convert
EXTRACT(EPOCH FROM INTERVAL '5 days 3 hours')/3600;
This would give hours since 60*60 = 3600
0
 
LVL 22

Expert Comment

by:earth man2
ID: 35152895
do you mean interval instead of timestamp ?
select round(cast ( extract(epoch from interval '19 days 06:17:00')as numeric )/3600.0, 2);
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:daniel_spiri
ID: 35274744
Earthman2,
When I run the query:

select round(cast ( extract(epoch from interval '19 days 06:17:00')as numeric )/3600.0, 2);

Result: 462.28

The minutes don't seem right.

The query on '19 days 06:01:00' returns 462.02.   (but it should be 462.01)
0
 
LVL 22

Accepted Solution

by:
earth man2 earned 500 total points
ID: 35286039
select div( cast (extract ( epoch from interval '19 days 06:17:00')as integer),3600)::text || ':' || extract( minute from interval '19 days 06:17:00');
0
 

Author Comment

by:daniel_spiri
ID: 35333541
Also, can you please help me in transforming this into a function?
0
 
LVL 22

Expert Comment

by:earth man2
ID: 35354874
create or replace function interval2dec( interval )returns text as $$
select div(cast (extract( epoch from $1)as integer),3600)::text || ':' || extract( minute from $1);
$$ language SQL;

select interval2dec( '19 days 06:17:00'::interval);
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Iteration: Iteration is repetition of a process. A student who goes to school repeats the process of going to school everyday until graduation. We go to grocery store at least once or twice a month to buy products. We repeat this process every mont…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now