Solved

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

Posted on 2012-03-31
2
424 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.

Join & Write a Comment

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

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

18 Experts available now in Live!

Get 1:1 Help Now