Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2012-03-31
2
Medium Priority
?
460 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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
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.  …
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 copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

596 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