Solved

How do i perform a calculation based on a specific time of the day in Oracle?

Posted on 2012-03-31
2
431 Views
Last Modified: 2012-03-31
I would like to calculate the minutes in Oracle if the time passes 1530. I am having trouble with the best way to hard code time time and cacalulate

Thanks so much!

 CASE WHEN
       TO_CHAR(ptoutor.tracking_time_in  ,'hh24mi') > '1530'
    THEN
      (15:30?? - ptinor.tracking_time_in ) * 1440
    else
     (ptoutor.tracking_time_in - ptinor.tracking_time_in  ) * 1440  
    END
0
Comment
Question by:MIREESE
2 Comments
 
LVL 20

Accepted Solution

by:
flow01 earned 500 total points
ID: 37791853
with tr
    as
    (select to_date('31/03/2012 14:00:03','dd/mm/yyyy hh24:mi:ss') ptoutor_tracking_time_in, to_date('31/03/2012 14:22:05','dd/mm/yyyy hh24:mi:ss') ptinor_tracking_time_in from dual
     union
     select to_date('31/03/2012 15:00:03','dd/mm/yyyy hh24:mi:ss') ptoutor_tracking_time_in, to_date('31/03/2012 14:22:05','dd/mm/yyyy hh24:mi:ss') ptinor_tracking_time_in from dual
     union
     select to_date('31/03/2012 15:28:00','dd/mm/yyyy hh24:mi:ss') ptoutor_tracking_time_in, to_date('31/03/2012 14:20:00','dd/mm/yyyy hh24:mi:ss') ptinor_tracking_time_in from dual
     union
     select to_date('31/03/2012 15:32:00','dd/mm/yyyy hh24:mi:ss') ptoutor_tracking_time_in, to_date('31/03/2012 14:20:00','dd/mm/yyyy hh24:mi:ss') ptinor_tracking_time_in from dual
     union
     select to_date('31/03/2012 16:00:03','dd/mm/yyyy hh24:mi:ss') ptoutor_tracking_time_in, to_date('31/03/2012 15:22:05','dd/mm/yyyy hh24:mi:ss') ptinor_tracking_time_in from dual
     union
     select to_date('31/03/2012 17:00:03','dd/mm/yyyy hh24:mi:ss') ptoutor_tracking_time_in, to_date('31/03/2012 15:22:05','dd/mm/yyyy hh24:mi:ss') ptinor_tracking_time_in from dual
    )
    select to_char(ptoutor_tracking_time_in, 'dd/mm/yyyy hh24:mi:ss'), to_char(ptinor_tracking_time_in, 'dd/mm/yyyy hh24:mi:ss'),  timedif * 1440 minutes
    from
    (
    select  ptoutor_tracking_time_in, ptinor_tracking_time_in,
    case
    when ptoutor_tracking_time_in - trunc(ptoutor_tracking_time_in)  > (15.5)/24
    then (trunc(ptoutor_tracking_time_in) + (15.5)/24 ) - ptinor_tracking_time_in
    else
     ptoutor_tracking_time_in   - ptinor_tracking_time_in
    end
    timedif
    from tr
    )
    order by ptoutor_tracking_time_in
/
0
 

Author Closing Comment

by:MIREESE
ID: 37792128
That worked perfectly.

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

Title # Comments Views Activity
null value 15 103
Oracle 10g - insert string with special characters 8 58
Oracle SQL Select unique values from two columns 4 55
Help on model clause 5 32
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

831 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