Solved

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

Posted on 2012-03-31
2
442 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
[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
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video shows how to recover a database from a user managed backup

733 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