Finding difference in time

Hi I want to find the difference in the time both are date fileds
login logout
1/24/2010 8:36:45 AM 1/24/2010 10:18:01 AM
1/25/2010 3:29:28 PM 1/25/2010 3:30:49 PM
rgds
ramya

You can use CASE and CAST, subtract the timestamps and only show the time component using SUBSTR
(I added column EARLY_IN, in case of workaholics ;) ) :
SQL> create table t as (
  2  select to_date('1/23/2010 7:45:45 AM', 'mm/dd/yyyy hh:mi:ss: AM') login, to_date('1/23/2010 06:05:30 PM', 'mm/dd/yyyy hh:mi:ss: AM') logout from dual union all
  3  select to_date('1/24/2010 8:36:45 AM', 'mm/dd/yyyy hh:mi:ss: AM'), to_date('1/24/2010 04:18:01 PM', 'mm/dd/yyyy hh:mi:ss: AM') from dual union all
  4  select to_date('1/26/2010 8:00:45 AM', 'mm/dd/yyyy hh:mi:ss: AM'), to_date('1/26/2010 01:20:43 PM', 'mm/dd/yyyy hh:mi:ss: AM') from dual union all
  5  select to_date('1/25/2010 8:10:28 AM', 'mm/dd/yyyy hh:mi:ss: AM'), to_date('1/25/2010 5:30:49 PM', 'mm/dd/yyyy hh:mi:ss: AM') from dual
  6  );
Table created.
SQL> select login
  2  ,      logout
  3  ,      case
  4            when to_date(to_char(login, 'hh24:mi:ss'), 'hh24:mi:ss') < to_date('08:00:00', 'hh24:mi:ss')
  5            then
  6              substr(( cast( to_date('08:00:00', 'hh24:mi:ss') as timestamp)+ to_char(login, 'dd')
  7                       -
  8                       cast(login as timestamp)
  9                     )
10                     , 12, 8
11                    )
12         end early_in
13  ,      case
14            when to_date(to_char(login, 'hh24:mi:ss'), 'hh24:mi:ss') > to_date('08:00:00', 'hh24:mi:ss')
15            then
16              substr(( cast(login as timestamp)
17                       -
18                       cast( to_date('08:00:00', 'hh24:mi:ss') as timestamp)
19                     )
20                     , 12, 8
21                    )
22         end late_in
23  ,      case
24            when to_date(to_char(logout, 'hh24:mi:ss'), 'hh24:mi:ss') < to_date('17:00:00', 'hh24:mi:ss')
25            then
26               substr((
27                        --
28                        cast( to_date('17:00:00', 'hh24:mi:ss') as timestamp)+ to_char(logout, 'dd')
29                        -
30                        cast(logout as timestamp)
31                      )
32                      , 12, 8
33                     )
34         end early_out
35  ,      case
36            when to_date(to_char(logout, 'hh24:mi:ss'), 'hh24:mi:ss') > to_date('17:00:00', 'hh24:mi:ss')
37            then
38               substr(( cast(logout as timestamp)
39                        -
40                        cast( to_date('17:00:00', 'hh24:mi:ss') as timestamp)
41                      )
42                      , 12, 8
43                     )
44         end late_out
45  from   t --<< change this table name into your own table name
46  /
LOGIN               LOGOUT              EARLY_IN LATE_IN  EARLY_OUT  LATE_OUT
23-01-2010 07:45:45 23-01-2010 18:05:30 00:14:15                     01:05:30
24-01-2010 08:36:45 24-01-2010 16:18:01          00:36:45 00:41:59
26-01-2010 08:00:45 26-01-2010 13:20:43          00:00:45 03:39:17
25-01-2010 08:10:28 25-01-2010 17:30:49          00:10:28            00:30:49Edited by: hoek on Jan 28, 2010 2:28 PM typo, a 'wokaholic' is someone who likes to cook I guess ;)

Similar Messages

  • How to find difference btw time?

    hi,
    Can any one tell me are there any function modules to perform add, diff(minus) operation on time fields?
    please let me know if you know any.
    thanks in advance,
    Prasad Babu.

    Hi,
    Try <b>CCU_TIMESTAMP_DIFFERENCE</b>
    CALL FUNCTION 'CCU_TIMESTAMP_DIFFERENCE'        
          EXPORTING                                  
               timestamp1 = timestamp1               
               timestamp2 = timestamp2               
          IMPORTING                                  
               difference = diff                     
          EXCEPTIONS                                 
               OTHERS     = 1.
    http://sap.ittoolbox.com/groups/technical-functional/sap-r3-dev/f-module-for-dates-subtraction-124376#
    Check out these threads
    date time difference
    FM to Difference between two data and time in tims data type
    Regards,
    Santosh

  • Find the Difference in time for creation of two activities for the same SR

    Hi
    I need to find the difference in time of cretaion of two different activities for an SR. Is there any function which I can use to get the same
    For e.g.
    SR # |Activity Created Date |Duration
    123 12-nov
    123 13 nov 1 day
    Thanks in advance
    Meena

    There's a TIMESTAMPDIFF function.
    An example from the book Oracle CRM On Demand Reporting has the following example...
    TIMESTAMPDIFF( SQL_TSI_MINUTE, Activity."Start Time", Activity."End Time" )
    which would return the difference in minutes.
    As I type this, I'm thinking you probably know this and your problem is how to get the Activity start time for the next activity into this function. I sorry can't think of any way to do that.

  • Finding difference between 2 databases

    Hi Folks,
    I have the following problem:
    I have 2 databases, database old, database new. Database new has modified/removed/added/inserted rows. Also columns in the db can also be modified. So what I have to do is to find the set of SQL statements which if I execute on database old, will make database old same as database new. Modification is only in data, not triggers etc.,
    I have explained my manager that this is not very easy to implement. Even finding difference between 2 DB is not trivial. Do you guys have any suggestion for me? whether in terms of implementing it or even convincing my boss is fine :)
    Are there any open source tools to do this? I am in big trouble now :(
    Thanks,

    Unless there is some other goal that you have not mentioned this is fairly easy.
    Just delete all the tables from the old database using SQL delete tables and then create new tables and populate them with data from the new database.
    Your SQL is basically just a serialization of the data in your new database.
    Anything else that you could do, such as calculating the differences from the one database to the other, and then creating a minimal edit list that will make the least possible number of changes must be weighed against the time it will take to write the code to compute the differences, the time it will take to debug the code and convince yourself that it is doing the right thing, and the time it will take to actually run.

  • DateDiff Help (Need time difference FROM Time 1 TO Time 2 - one direction)

    I hope I am putting this in the right section. This is my first post. Thank you all ahead of time for your help.
    I am new to both SQL and Report Builder so please bear with me and thank you ahead of time.
    I need to find the time difference (in minutes) between Time 1 and Time 2. I've figured out the basics in how to do this but I need the logic to work in ONE DIRECTION. Meaning I need the statement to find the difference STARTING FROM TIME 1 and then ENDING
    WITH TIME 2. I need the statement to always assume that Time 1 is FIRST and that Time 2 is LAST.
    Here's an example of my results now with a basic DateDiff statement.
    Time 1 | Time 2 | Time Difference (in minutes)
    11:30 | 1/15/2015 11:50:00 AM | 20
    23:50 | 1/15/2015 12:00:00 AM | 1430
    23:45 | 1/15/2014 2:05:00 AM | 1300
    Please note that Time 1 does NOT have a date at all and came over from its table as a simple 4 digit string so I had to convert it to datetime format using a concatenate statement. If it DID have a date then this probably wouldn't be a problem.
    Thoughts?
    Thanks.

    Thanks, Patrick. I'll look into understanding that (I'm still new to both SQL and Report Builder). Could you explain to me what it does?
    I was able to answer my own question only to find that it didn't quite work the way I need it to. I was able to make the logic work so that "if the time is 12AM then change the date for Time 1". However, I ran into another problem and realize that
    I ultimately just need to get this to work in one direction. Meaning I need it to find the difference in time STARTING from the Time 1 field TO the Time 2 field. Here's why (using the statement I got to work but only for 12AM):
    Time 1 | Time 2 | Time Difference (in minutes)
    23:45 | 1/15/2014 2:05:00 AM | -1300

  • Difference between Time dimension and product(regular) dimenstion

    Hi All,
    I would like to know what is the difference between time dimenstiona and regular dimenstion. How can we differentiate and how Oracle bi server knows a dimension
    as Time dimenstion.
    Thanks,

    Hi,
    By using Logical Dimensional Structure and chronological keys it identify time or other types of dim.
    Just double clik time dimension then you can find the
    root type (Time, Ragged and skipped) and for the chronological keys > just double click logical level then select keys tab -- here u can find chronological keys
    Thanks
    Deva

  • HT201250 What if Time Machine can't find my airport time capsule?

    I can't find my airport time capsule on my computer... I need help in order to reach documents saved on my airport time capsule used as an external hard drive... Please help!

    Is it listed in the sidebar of a Finder window, under SHARED?

  • Is there a way to find exactly when a certain web page was visited? I know if I go to Tools/Page Info, I can see how many times that page was visited, but I would like to know if I can find the exact time and date. Thank you.

    I am using Firefox version 3.6.13

    You can find the last time a web page was visited by using the Library.
    In the History menu select "Show All History" to open the Library. You can use the Library to view the history, and by default it will show the last date & time the site was visited. If the Visit Date column is not visible, within the Library select Views, then Show Columns, then Visit date to display that column.

  • How to find how many times a t code has been processed by a user

    How to find how many times a t code has been processed by a user I am not able to get the exact number from the ST03 or STAD/STAT transaction. I am requiring the specific number that this T code has been processed completely this many no of times for a specific period.

    You must be more precise with your question.
    How long is the time period which you want to check, few hours or several days or longer? And how many executions do you expect, 100, 10000 or millions?
    The STAD should help you, for the smaller numbers. There is no solution for the larger ones. Don't mix STAD and ST03, ST03 is aggregated STAD information
    and know only how often a transaction was executed in total.
    ST05 is no solution for your problem to much overhead, and yoou should trace only a short period.
    There is no tool to check usage of transactions in more detail because of privacy reasons.
    Siegfried

  • How to find out insertion time of records in an oracle table

    Hi everybody,
    I have a table with about 50,000 records in my Oracle database and there is a date column which shows the date that each record get inserted to the table, for example 04-Aug-13.
    Is there any way that I can find out what time each record has been inserted?
    For example: 04-Aug-13 4:20:00 PM. (For my existing records not future ones)
    I searched over the internet and find some results but none of them seem to be practical.
    Thanks for your help.

    I have a table with about 50,000 records in my Oracle database and there is a date column which shows the date that each record get inserted to the table, for example 04-Aug-13.
    Is there any way that I can find out what time each record has been inserted?
    For example: 04-Aug-13 4:20:00 PM. (For my existing records not future ones)
    First you need to clarify what you mean by 'the date that each record get inserted'.  A row is not permanent and visible to other sessions until it has been COMMITTED and that commit may happen seconds, minutes, hours or even days AFTER a user actually creates the row and puts a date in your 'date column'.
    Second - your date column, and ALL date columns, includes a time component. So just query your date column for the time.
    The only way that time value will be incorrect is if you did something silly like TRUNC(myDate) when you inserted the value. That would use a time component of 00:00:00 and destroy the actual time.

  • What's the difference between time capsule and time machine?

    What is the difference between time capsule and time machine?

    See Using Time Machine with a Time Capsule.

  • How to find the Latency time in java.

    How to find the Latency time in java.

    long start = System.currentTimeMillis();
    doTheWork();
    long durationInMillis = System.currentTimeMillis() - start;You might repeat doTheWork() several (100-1000 or more) times if it is fast and the granularity of your system clock is not good enough.

  • Hello find my mac displays offline when I'm using the actual mac I want to find at the time, can anyone help?, Hello find my mac displays offline when I'm using the actual mac I want to find at the time, can anyone help?

    Hello find my mac displays offline when I'm using the actual mac I want to find at the time, can anyone help?, Hello find my mac displays offline when I'm using the actual mac I want to find at the time, can anyone help?

    Welcome to the Apple community.
    Is your Mac connected to the network via ethernet. Mac's thatareI connected via ethernet cannot be located using "find my phone".

  • Genius Bar lost a business file. Can't seem to find it in Time Machine...Got Ideas?

    Genius Bar lost a business financial file. Can't seem to find it in Time Machine. Gone back several days...Got Ideas?

    You need to give me more info..
    What did you take the Mac to the genius for??
    What did they do to it?
    Did you have TM setup at defaults doing backups hourly?
    Are you using a Time Capsule? Did you ever backup the time capsule??
    Please do a backup of your Time Machine backup right now.. in TC plug in a suitable sized USB drive and do an archive.. you can do nothing else while this is happening but it is crucial for you to have another copy of whatever you have.
    Archive is a bit slow.. and the backup is slightly less useful.
    The fastest method is plug the USB into your computer and copy and paste  the backups.backupdb directly to the USB drive. It should copy at around 60GB/hr so calculate how long that will take. See instructions here. http://pondini.org/TM/18.html Assuming you are using a TC then you use method 4.. copying from a Network backup to local drive.
    Never work directly from the original backup .. work just from this copy so anything you do can be reversed or recovered.
    Read very carefully the methods of restoring files from TM.. it is a bit out of date but Pondini has the best details.
    So Q14-17 here. http://pondini.org/TM/FAQ.html
    You can do a full recovery of the backup to a USB drive.. and then search for your file in more normal way.
    Get professional help.. and this is where you need data recovery people who are familiar with apple TM backup format. Check local apple store or perhaps better local Apple independent repair business that are used to handling this kind of event.
    Also talk to the company that makes the software as they must have to deal with people who manage to lose, corrupt or in some other way ruin their data and need to recover.. see what hints they can give you.
    Surely at some point you pass your info to your accountant in the form of a computer backup file from your accounting package.
    I have to admit I am surprised if you never backed up your business data file to a USB stick and put it in a filing cabinet at home or a hard disk at a friends place.. Cloud storage for your business files.. Did you depend totally on TM for backups? You never planned for a fire or theft of your computer and TC?? Or what has happened.. loss of computer files and failure of the backup? No greater teacher than the burnt hand that touching hot stuff isn't a good idea. Sorry .. it is a very hard lesson.. but electronic data storage on magnetic media is ever one byte away from being gone forever.. !!

  • SQL Query issue find difference in records

    Hi All,
    I am using oracle 10g. I need urgent help in finding difference in records based on date:
    I have table sales as below:
    salesman SALES_COUNT DATE
    JOHN 20 04/01/2012
    DENNY 15 04/01/2012
    JOHN 30 04/02/2012
    DENNY 30 04/02/2012
    JOHN 45 04/03/2012
    DENNY 50 04/03/2012
    SALES_COUNT is increasing for sales man with date. Its like cumulative count. John has total sales from 04/01/2012 to 04/03/2012 is 50 and same case with Denny. This SALES_COUNT will keep on increasing with dates as sales keep adding in the table for each salesman.
    But i want to have seprate counts for each salesman.
    for e.g: SALES_COUNT JOHN on 04/02/2012 is 30-20 =10
    SALES_COUNT JOHN on 04/03/2012 is 45-30 =15
    SALES_COUNT DENNY on 04/02/2012 is 30-15 =15
    SALES_COUNT JOHN on 04/03/2012 is 50-30 =20
    Please help me with this scenario and let me know if need more information. I will greatly appreciate your help.
    Thanks.

    Does this give you what you want?
    with t as (
         select 'JOHN' salesman, 20 sales_count, to_date('04/01/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'DENNY' salesman, 15 sales_count, to_date('04/01/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'JOHN' salesman, 30 sales_count, to_date('04/02/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'DENNY' salesman, 30 sales_count, to_date('04/02/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'JOHN' salesman, 45 sales_count, to_date('04/03/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'DENNY' salesman, 50 sales_count, to_date('04/03/2012', 'mm/dd/yyyy') sale_date from dual
    select salesman,
           sales_count sales_todate,
           sale_date,
           sales_count - lag(sales_count, 1, 0) over (partition by salesman order by sale_date) daily_sales
    from t
    SALESMAN,SALES_TODATE,SALE_DATE,DAILY_SALES
    DENNY,15,4/1/2012,15
    DENNY,30,4/2/2012,15
    DENNY,50,4/3/2012,20
    JOHN,20,4/1/2012,20
    JOHN,30,4/2/2012,10
    JOHN,45,4/3/2012,15
         

Maybe you are looking for

  • How can I read my ebook on a hand held?

    I bought $350 worth of ebooks from ebooks.com. They have no support and refer all of their technical questions to Adobe, so I hope someone from here can answer me. These are the instructions on how to transfer the ebook to the hand held on the ebooks

  • [SOLVED]Gnome 3 only fallback mode

    I've got an ati radeon hd 4350 graphics-card. I'm using the radeon driver. But, gnome 3 will only boot in fallback mode. Mesa-demos is installed. Glxinfo | grep rendering yields "direct rendering: Yes". According to Gnome 3 system info, my graphics d

  • Router will connect to computer but not internet

    My WRT54GS  will connect wirelessly to my computer,but will not connect to the internet.  To get on the net, I have plug the line from the cable modem to my pc.  Any suggestions?

  • InDesign 6 not responding when adding new pages

    Hi folks, I'm having a continuing problem that sees InDesign 6 "not responding" every time I try to add a new page or duplicate a spread on a document I'm working on. This doesn't seem to be a problem on a new document - only on my working file, whic

  • In Jdeveloper11+ADF BC how to find disclosed tab

    hi, In Jdeveloper11+ADF BC how to find disclosed tab... or wheather the a purticular tab is disclosed or not.. in details, i have a ADF panellTabbed with two ShowdetailItems. I have a common button out side the tab. i want to identify which showdetai