Solved

oracle query with drive hour and capacity calculation

Posted on 2014-10-29
9
220 Views
Last Modified: 2014-10-29
http://www.experts-exchange.com/Database/Oracle/Q_28541483.html

Closed

It was my mistake when I explained as to what was required.

drop table tab1 purge;
create table tab1(start_time date, end_time date,machines number);

Insert into TAB1
   (start_TIME, end_TIME,machines)
 Values
   (
   TO_DATE('10/01/2014 14:00:00', 'MM/DD/YYYY HH24:MI:SS'),
   TO_DATE('10/01/2014 19:30:00', 'MM/DD/YYYY HH24:MI:SS'),2);

commit;


select to_char(start_time,'HH12:MI:SS AM') starttime,
          to_char(end_time,'HH12:MI:SS AM') endtime from tab1

Now I want the total drive hours end_time minus start_time ( in the format 5.5)
or 4  hour drive as 4

and the hours has to be divided by 2 and always round it down. This number has to be multiplied by no of machines used to draw. Now I get the capacity.

capacity = (hours /2 ) * machines
0
Comment
Question by:anumoses
9 Comments
 
LVL 6

Author Comment

by:anumoses
ID: 40410932
select  TRIM(TO_CHAR(TRUNC(((86400*(end_time - start_time))/60)/60)-24*(trunc((((86400*(end_time - start_time))/60)/60)/24)),'00')) ||'.'||
    TRIM(TO_CHAR(TRUNC((86400*(end_time - start_time))/60)-60*(trunc(((86400*(end_time - start_time))/60)/60)),'00')) ||'.'  as drive_hours

Tried but did not get correct number.
0
 
LVL 13

Expert Comment

by:Alexander Eßer [Alex140181]
ID: 40410940
select (((end_time - start_time) * 24) / 2) * machines
  from tab1;

Open in new window


btw: what exactly do you expect as result?!
0
 
LVL 6

Author Comment

by:anumoses
ID: 40411032
I just need the drive hours in number format. For the example above I need as 5.5
0
 
LVL 6

Author Comment

by:anumoses
ID: 40411070
The problem in my calculation is the date part in my database is not correct. If the drive is for today the date part says some day in 2010. So I have to only take hours and minutes in calculation the drive hours.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 6

Author Comment

by:anumoses
ID: 40411125
CREATE TABLE TAB1
(
  DRIVE_DATE   DATE                             NOT NULL,
  DRIVE_ID     NUMBER(7)                        NOT NULL,
  START_TIME   VARCHAR2(8 BYTE),
  END_TIME     VARCHAR2(8 BYTE),
  DRIVE_HOURS  NUMBER
)




Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/01/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024984, '10:30:00', '02:30:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/01/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025401, '10:00:00', '02:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/01/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024089, '08:30:00', '03:00:00', 6.5);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/01/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025416, '10:00:00', '02:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/01/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024983, '03:30:00', '07:30:00', -22628);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/01/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2023342, '10:00:00', '02:00:00', -16076);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/01/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025327, '09:00:00', '03:30:00', 6.5);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/01/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025216, '10:00:00', '01:30:00', 3.5);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/01/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025299, '12:00:00', '04:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/02/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025033, '08:30:00', '02:00:00', 5.5);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/02/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2023796, '02:00:00', '06:30:00', 24844.5);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/02/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024586, '08:30:00', '12:30:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/02/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024985, '08:00:00', '02:00:00', 6);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/02/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2023436, '03:30:00', '07:30:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/03/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024986, '08:00:00', '12:00:00', -59900);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/03/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025313, '01:00:00', '05:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/03/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025329, '10:00:00', '02:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/03/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024988, '08:50:00', '01:50:00', 5);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/04/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025023, '09:30:00', '02:00:00', 4.5);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/04/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2023322, '10:00:00', '02:00:00', 8764);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/04/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025302, '10:00:00', '02:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/04/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024779, '07:30:00', '11:30:00', 24100);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/04/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024990, '09:00:00', '01:00:00', -19004);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/04/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025292, '10:00:00', '02:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/04/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025213, '09:30:00', '01:30:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/05/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2023320, '08:00:00', '12:30:00', 4.5);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/05/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2022795, '09:00:00', '01:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/05/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2023279, '08:00:00', '11:00:00', 3);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/05/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2023486, '08:00:00', '12:30:00', 10228.5);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/05/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2022848, '08:00:00', '12:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/05/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2023482, '08:00:00', '12:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/06/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2022915, '09:30:00', '12:30:00', 3);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/06/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025334, '01:30:00', '06:00:00', 4.5);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/06/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2022856, '03:00:00', '07:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/06/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2023399, '03:30:00', '07:30:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/07/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025462, '04:00:00', '07:30:00', 3.5);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/07/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2023224, '03:30:00', '07:30:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/07/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025448, '03:00:00', '07:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/07/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025659, '03:00:00', '07:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/07/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024994, '11:00:00', '04:00:00', 725);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/07/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024978, '04:00:00', '07:30:00', 3.5);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/07/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025369, '11:00:00', '03:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/07/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024995, '09:00:00', '01:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/07/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025408, '10:00:00', '04:00:00', 6);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/07/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024024, '08:15:00', '02:00:00', -20418.25);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/07/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025012, '08:00:00', '01:45:00', -20490.25);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/08/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025018, '08:30:00', '01:00:00', 4.5);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/08/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024997, '02:00:00', '07:30:00', 5.5);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/08/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025648, '10:00:00', '02:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/08/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024998, '07:00:00', '12:00:00', 5);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/08/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025000, '08:00:00', '02:00:00', 6);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/08/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025001, '01:00:00', '07:00:00', 6);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/08/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2022936, '08:00:00', '12:00:00', 9508);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/08/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025017, '08:00:00', '01:45:00', -20490.25);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/08/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025002, '10:30:00', '01:15:00', 2.75);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/09/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024908, '09:00:00', '03:00:00', 6);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/09/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025189, '03:00:00', '07:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/09/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025004, '08:30:00', '02:30:00', 6);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/09/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025005, '10:00:00', '02:00:00', -9500);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/09/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025221, '03:30:00', '07:00:00', 3.5);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/09/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024944, '03:30:00', '07:30:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/09/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024405, '02:00:00', '06:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/09/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2023140, '11:00:00', '04:00:00', 5);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/09/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025452, '03:30:00', '07:30:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/10/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024613, '07:30:00', '01:30:00', 6);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/10/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024686, '09:00:00', '01:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/10/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024619, '08:30:00', '01:30:00', 4421);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/11/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025746, '10:00:00', '02:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/11/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2023466, '08:00:00', '12:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/11/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025008, '09:00:00', '01:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/11/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025321, '12:30:00', '04:30:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/11/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025319, '10:00:00', '02:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/11/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2023188, '07:30:00', '11:30:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/11/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2022794, '09:00:00', '01:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/11/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025317, '09:00:00', '02:00:00', -739);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/11/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024949, '08:00:00', '12:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/12/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025391, '08:00:00', '12:30:00', 1468.5);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/12/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2022599, '09:00:00', '01:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/12/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024462, '08:30:00', '12:30:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/12/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025373, '08:30:00', '12:00:00', 3.5);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/12/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2023182, '08:00:00', '12:30:00', 13852.5);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/13/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025009, '03:30:00', '07:30:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/13/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2022947, '10:00:00', '03:00:00', 5);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/13/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025003, '09:00:00', '03:00:00', 17526);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/13/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025839, '03:30:00', '07:30:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/13/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025295, '03:30:00', '07:30:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/13/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025010, '03:00:00', '07:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/14/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024853, '07:30:00', '02:00:00', 6.5);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/14/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025397, '12:15:00', '05:15:00', 5);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/14/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025011, '10:00:00', '02:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/14/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2023704, '03:15:00', '07:30:00', -50395.75);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/14/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2023710, '08:00:00', '02:00:00', 6);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/14/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025188, '09:00:00', '01:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/14/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024996, '07:45:00', '12:45:00', 5);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/14/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2024801, '08:00:00', '12:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/15/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025013, '11:00:00', '02:00:00', 3);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/15/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025014, '10:00:00', '03:00:00', 7301);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/15/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025015, '01:30:00', '07:30:00', -9498);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/15/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025016, '10:00:00', '02:00:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/15/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2023138, '12:30:00', '04:30:00', 4);
Insert into TAB1
   (DRIVE_DATE, DRIVE_ID, START_TIME, END_TIME, DRIVE_HOURS)
 Values
   (TO_DATE('10/15/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 2025423, '10:30:00', '02:30:00', 4);
COMMIT;

Open in new window


If you look at the data I am having problem when start time is 3.30 and end time is 7.30 I need am or pm here. That is why (end_time-start_time)*24 drive_hours is not working for me
0
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 40411192
Take all your previous questions about date and time manipulation.
Think about what the results you are wanting and formulate what you need to do to get the results.

From the last question:
You have the 'hours' and 'minutes'.
Minutes to fractional hours is minutes/60.

You get 5.5 from the first example, simple tweak from the SQL in the last question:
select 
  trim(extract(hour from numtodsinterval(to_date(to_char(end_time,'HH24:MI:SS'),'HH24:MI:SS')-to_date(to_char(start_time,'HH24:MI:SS'),'HH24:MI:SS'),'day'))) || 
  case when trim(to_char(extract(minute from numtodsinterval(to_date(to_char(end_time,'HH24:MI:SS'),'HH24:MI:SS')-to_date(to_char(start_time,'HH24:MI:SS'),'HH24:MI:SS'),'day')),'00'))  > 0 then 
  trim(to_char(extract(minute from numtodsinterval(to_date(to_char(end_time,'HH24:MI:SS'),'HH24:MI:SS')-to_date(to_char(start_time,'HH24:MI:SS'),'HH24:MI:SS'),'day')),'00'))/60
  end  mytime
from tab1
/
                                          

Open in new window

0
 
LVL 32

Expert Comment

by:awking00
ID: 40411222
If your start times and end times are truly date datatypes, then use them to do your date math calculations and only use to_char for purposes of displaying the results. Please post a describe of your table and the results of the following query:

select start_time, to_char(start_time,'DD-MON-YYYY') display_start, end_time, to_char(end_time,'DD-MON-YYYY') display_end
from yourtable;

It's probably better for you to show us exactly what you're dealing with, then we can ask the questions to best determine what you need to do.
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40411234
awking00,
Read the previous question.

The data is all messed up.  The columns are date data types but the actual date portion doesn't matter and the start date can be after the end date.

Only the time portion of the column matters.
0
 
LVL 6

Author Closing Comment

by:anumoses
ID: 40411449
Thanks
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

867 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

15 Experts available now in Live!

Get 1:1 Help Now