?
Solved

Minutes(Number Column) to HH24MM

Posted on 2000-05-15
8
Medium Priority
?
670 Views
Last Modified: 2008-03-17
Good Morning

Have a table with a defined column elapsed_time(number).

example 90 minutes

I want to convert it to HH24MM.

example 0130

Is this possible in Oracle 8i.

Thanks
0
Comment
Question by:tomatocans
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 5

Expert Comment

by:sbenyo
ID: 2810472
There is no time datatype in oracle but you can change the field to a date field like this:

alter table <table-name> modify (elapsed_time date);

Then insert values like this:

insert into <table-name> values (to_date('0130','HH24MI'));

This will store the time value.
If you want to make comparisions on it also use the same format:

select * from <table-name> where elapsed_time > to_date('0230','HH24MI');


0
 

Author Comment

by:tomatocans
ID: 2810632
what if u have 60,000 records with elapsed time
fields u need to update
0
 
LVL 35

Expert Comment

by:Mark Geerlings
ID: 2810802
There is also another issue.  Oracle date columns always contain a date value, whether they contain the time protion or not.  If you succeed in storing values when you have supplied only the time (I am not sure that Oracle will accept that) you may still have problems doing comparisons or arithmetic based on those values if the days are different.  I am assuming that Oracle will use the current sysdate for the date portion, so a record created just before midnight one day will have a different date than a records created moments later after midnight.

Have you tested this?
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Expert Comment

by:erezal
ID: 2811308
Why do you want to convert a field
containing elapsed time to a "HH24:MM"
mask?

In what ways are you using the field
(Comparisons,calculations,showing only)?
0
 
LVL 1

Expert Comment

by:nitinpai
ID: 2811458
Hi,
  The problem definition is not clear. But from what I have interpreted, u have a column of number datatype which is actually storing the elapsed time. Now, u want to update the values so that it will be in the format hhmi. Ok. Then u can run the following statement:
update tmp
set elapsed_time = floor(elapsed_time/60)||mod(elapsed_time,60);

Note that u cannot have the format 0130 bcos the datatype is a number and not a character.

The above statement will update the value elapsed_time = 90 to elapsed_time = 130. However, if the elapsed_time = 1440 the value will be converted to 240. Now, if the elapsed_time is greater than 24 hrs, what format do u want it to be in?? Pl. give examples. The solution is always available.

0
 
LVL 35

Expert Comment

by:Mark Geerlings
ID: 2811701
Have you considered creating a view using a calculation like the one suggested by nitinpai, instead of altering your table?  This has the advantage of not requiring an update, and being able to display all of the records as if they had been updated.

Can you explain the advantage(s) you see in having the data stored as something other than a number?
0
 
LVL 1

Accepted Solution

by:
sohill earned 200 total points
ID: 2816420
use this sql :
select to_char(to_date(lpad(trunc(&1/60),2,'0')||lpad(MOD(&1,60),2,'0'),'HH24MI'),'HH24:MI')  
from dual

and subsitute &1 by your parameter, e.g. 90
0
 

Author Comment

by:tomatocans
ID: 2830674
Thanks
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

801 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