Difference in Minutes

I want to calculate minutes between these 2 rows:
My input data looks like:
id cola colb colc cold
123 12/14/2004 7:15:00 AM 12/14/2004 5:00:00 PM 12/14/2004 7:15:00 AM 12/14/2004 5:00:00 AM
123 12/14/2004 12:30:00 AM 12/14/2004 5:00:00 PM null null
Output looks like:
id cola colb cole colc cold colg
123 12/14/2004 7:15:00 AM 12/14/2004 5:00:00 PM 855 12/14/2004 7:15:00 AM 12/14/2004 5:00:00 AM 585
cole --> sum of difference of minutes between colb and cola from row 1 & 2
colg ---> difference in minutes between cold and colc
Thanks in advance

alter session set nls_date_format = 'MM/DD/YYYY HH:MI:SS PM'
with t as (
           select 123 id,to_date('12/14/2004 7:15:00 AM') cola,to_date('12/14/2004 5:00:00 PM') colb,to_date('12/14/2004 7:15:00 AM') colc,to_date('12/14/2004 5:00:00 AM') cold from dual union all
           select 123,to_date('12/14/2004 12:30:00 AM'),to_date('12/14/2004 5:00:00 PM'),to_date(null),to_date(null) from dual
select  id,
        cola,
        colb,
        trunc((colb - cola) * 24 *60) cole,
        colc,
        cold,
        trunc((cold - colc) * 24 *60) colg
  from  t
        ID COLA                   COLB                         COLE COLC                   COLD                         COLG
       123 12/14/2004 07:15:00 AM 12/14/2004 05:00:00 PM        585 12/14/2004 07:15:00 AM 12/14/2004 05:00:00 AM       -135
       123 12/14/2004 12:30:00 AM 12/14/2004 05:00:00 PM        990
SQL> SY.

Similar Messages

  • SUBSTRACTING 2 DATES TO GET THE DIFFERENCE IN MINUTES

    Hi
    I want to substract 2 dates and to get the difference in minutes. Can you help me with that ?
    Thanks

    select (sysdate - (sysdate - 10)) * 24 * 60 from dual
    where
    sysdate - date1
    (sysdate -10) - date2
    24 - number of hours per day
    60 - number of minutes per hour
    Is this what you need?

  • Date difference in minutes

    Is there any function module which can give difference between dates with associated time in minutes ?
    Eg. Difference between
        16.10.2006 - 12:00:40
        and
        17.10.2006 - 15:00:00

    hi , use this function module,
    L_TO_TIME_DIFF
    the o/p is like this..
      Import parameters               Value                                                                               
    I_START_DATE                    10/12/2006            
      I_START_TIME                    12:00:00              
      I_END_DATE                      10/12/2006            
      I_END_TIME                      12:00:30              
      I_TIME_UOM                      MIN                                                                               
    Export parameters               Value                                                                               
    E_TIME_DIFF                                 0.500     
    2...
      Import parameters               Value               
      I_START_DATE                    10/12/2006          
      I_START_TIME                    12:00:00            
      I_END_DATE                      10/18/2006          
      I_END_TIME                      12:00:30            
      I_TIME_UOM                      MIN                                                                               
    Export parameters               Value               
      E_TIME_DIFF                             8,640.500   
    hope this helps ,
    regards,
    vijay

  • Difference in minutes for two timestamp values

    Dear All,
    I am having two timestamp values and need to calculate the total time in minutes between them and store in a variable.
    Can you please help me.
    Eg:
    T1 = 12-APR-12 06.01.56.000000 AM
    T2 = 10-APR-12 06.14.32.000000 AM
    I want to have T3 as the total time difference beteween T1 and T2 in minutes.
    Not able to convert +000000001 23:47:24.000000000 in minutes
    The above value I got was by just substracting T1 and T2
    Thanks!

    /* Formatted on 2012/04/12 15:56 (Formatter Plus v4.8.8) */
    DECLARE
       v_time1       date;
       v_time2       date;
       v_time_diff   number;
    BEGIN
       SELECT To_Date(TO_CHAR (wss_gdp_time, 'DD-MON-YYYY HH12:MI:SS'),'DD-MON-YYYY HH12:MI:SS')
         INTO v_time1
         FROM tab1
        WHERE wss_gdp_time = (SELECT MAX (wss_gdp_time)
                                FROM tab1) AND ROWNUM <= 1;
       SELECT to_Date(TO_CHAR (wss_gdp_time, 'DD-MON-YYYY HH12:MI:SS'),'DD-MON-YYYY HH12:MI:SS')
         INTO v_time2
         FROM tab1
        WHERE wss_gdp_time = (SELECT MAX (wss_gdp_time)
                                FROM tab1
                               WHERE wss_gdp_time < (SELECT MAX (wss_gdp_time)
                                                       FROM tab1))
          AND ROWNUM <= 1;
       SELECT ((v_Time1-v_time2) * 1440)
         INTO v_time_diff
         FROM DUAL;
       DBMS_OUTPUT.put_line (v_time1 || ' ' || v_time2 || ' ' || v_time_diff);
       IF v_time_diff > '10'
       THEN
          DBMS_OUTPUT.put_line ('ALERT');
       ELSE
          DBMS_OUTPUT.put_line ('No ALERT');
       END IF;
    END;
    /

  • Need date difference in Minutes

    Hi,
    I want to get the difference of date in minute.
    Please help me out.
    format is mentioned below in the query
    select (to_date('9/19/2007 8:02:33 PM', 'MM/DD/RRRR HH12:MI:SS AM')
         - to_date('9/19/2007 7:02:02 PM', 'MM/DD/RRRR HH12:MI:SS AM'))
    from dual
    Regards
    Amit

    This?:
    SQL>  with date_diff as
         (select to_timestamp ('9/19/2007 8:02:33 PM',
                               'MM/DD/RRRR HH12:MI:SS AM'
                 - to_date ('9/19/2007 7:02:02 PM', 'MM/DD/RRRR HH12:MI:SS AM')
                                                                               dt
            from dual)
    select extract (day from dt) * 24 * 60
         + extract (hour from dt) * 60
         + extract (minute from dt)
         + extract (second from dt) / 60 min
      from date_diff
           MIN
    60.5166667

  • 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.

  • How to calculate Time difference for a single line item

    Hi All,
    I have an issue where you have to calculate the Start time and End Time , Start Date and End Date for a particular Work item number
    For eg ;
    WI_ID WI_CD WI_CT
    000001312610 02/09/2009 09:48:4 02/09/2009 09:48:9
    000001312610 02/09/2009 09:54:4 02/09/2009 09:54:9
    000001312610 02/09/2009 09:54:5 02/09/2009 09:54:9
    000001312610 02/09/2009 10:07:0 02/09/2009 10:07:9
    000001312610 02/09/2009 10:07:0 02/09/2009 10:07:9
    000001312610 02/09/2009 10:16:5 02/09/2009 10:16:9
    000001312610 02/09/2009 10:16:7 02/09/2009 10:16:9
    Similarly I get the Endtime and ENd dayfrom other table for same work item.So my requirement here is
    in the it should show the display in a single cell .as, 5secs, 5 secs,4 secs,9secs,4 secs,2 secs
    for each work item.
    Can any body help me on this issue.
    Any pionters for this are much helpful for me.
    Thanks
    Rohini.

    Timestamp is date and time together in one field..
    Search for data element TIMESTAMP.
    If you are getting this in your table.
    If you are getting time and date in different fields then you can use the function module
    given below....
    CALL FUNCTION 'DELTA_TIME_DAY_HOUR'
      EXPORTING
        t1            =
        t2            =
        d1            =
        d2            =
    IMPORTING
       MINUTES       =
    Then you can convert minutes into seconds..
    Function module credit to BrightSide it works....but only it will give difference in minutes
    Regards,
    Lalit Mohan Gupta.

  • 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

  • How to set just hour and minute to a Calendar object and do comparsion

    hi there
    can anyone show me how to just set the time : hour and minute to a calendar obj and do comparion? for instance, compare mid night with 7:24pm, how do i create objects to do it? thanks

    Or I'll just post them here to save the trouble...
        Calendar xmas = new GregorianCalendar(1998, Calendar.DECEMBER, 25);
        Calendar newyears = new GregorianCalendar(1999, Calendar.JANUARY, 1);
        // Determine which is earlier
        boolean b = xmas.after(newyears);            // false
        b = xmas.before(newyears);                   // true
        // Get difference in milliseconds
        long diffMillis = newyears.getTimeInMillis()-xmas.getTimeInMillis();
        // Get difference in seconds
        long diffSecs = diffMillis/(1000);           // 604800
        // Get difference in minutes
        long diffMins = diffMillis/(60*1000);        // 10080
        // Get difference in hours
        long diffHours = diffMillis/(60*60*1000);    // 168
        // Get difference in days
        long diffDays = diffMillis/(24*60*60*1000);  // 7

  • Question about Time differential in minutes

    Post Author: Jeff Goddard
    CA Forum: Formula
    I am trying to figure out how to display the difference in minutes between two results- the earliest result of a specific day, and the latest result of a specific day.  For each separate day, I need to display this.  Any suggestions?  Thanks.

    Post Author: Jeff Goddard
    CA Forum: Formula
    I have a list of testresults, each with a date and time associated with them.  there is a number of the taken each day.  example: Test Date 08-Nov-2007  13:50:5008-Nov-2007  15:57:1408-Nov-2007  22:12:4109-Nov-2007  07:33:0409-Nov-2007  21:22:17  This is an example of a column in the report which is the testresults.testdate field.  In this example I would need to display the time difference between the first result- (the earliest on Nov. 8, to the third result which would be the latest on Nov. 8).  Then the same thing for Nov.9(earliest, latest) and so on.  I'm guessing it has something to do with the minimum and maximum function, just not sure how to get it to reference the specific day.

  • Time Difference Please help

    I want to take the current date/time and save it into a Timestamp database field
    After sometime (depent on the user)
    I do the the same thing (take the current date/time and save it into a Timestamp database field)
    and after i subtract the last timestamp from the 1st and take the difference in minutes.
    I would prefer a sample code
    although any help is appreciated!

    This is easy enough that I'll let you code it. Use the getTime() method of java.sql.TimeStamp. This returns a long value. Subtract the later from the earlier, divide by 60000 ( # of milliseconds in a minute) and you have you answer.
    Details left to you.
    Cheers
    DB

  • How to calculate the minutes

    I've got two fields of type VARCHAR2(5) containing the time in (24)hours and minutes (for example 14:00)
    I want to get the difference in minutes between the two fields.
    For example if I've got:
    start  varchar2(5) := '14:00';
    finish varchar2(5) := '13:30';
    I want to get:
    *30* or event better *0,5* (hours).
    Take into account that the two variables refer to the same date (day).
    I've tried with something like this but without success
    select to_date(start,'hh24:mi') first,
    to_date(finish,'hh24:mi') second,
    to_date(start,'hh24:mi') - to_date(finish,'hh24:mi') difference
    from dual;
    FIRST                                    SECOND                             DIFFERENCE
    *01/06/2010 14.00.00 01/06/2010 13.30.00 0,0208333333333333*
    Can you help me?

    Mark1970 wrote:
    I've tried with something like this but without success
    select to_date(start,'hh24:mi') first,
    to_date(finish,'hh24:mi') second,
    to_date(start,'hh24:mi') - to_date(finish,'hh24:mi') difference
    from dual;
    FIRST                                    SECOND                             DIFFERENCE
    *01/06/2010 14.00.00 01/06/2010 13.30.00 0,0208333333333333*
    Can you help me?You almost had it right there. you just forgot to multiply the result (which is a fraction of a day) by 24 to give the number of hours.
      1* select 0.0208333333333333*24 from dual
    SQL> /
    0.0208333333333333*24
                       .5
    SQL>

  • Difference between systimestamp and a column of timestamp

    Hi ,
    I want to get the minutes difference between systimestamp and a column which has value of certain timestamp
    Table1
    InsertTmstmp --> 03-FEB-10 01.43.07.865272000 AM
    now how can I get the difference in minutes between systimestamp - InsertTmstmp ?
    I tried the following
    select EXTRACT(minute FROM systimestamp - InsertTmstmp ) from table1 where seq_id = '9';
    but this was not giving proper results .
    For example if InsertTmstmp --> 03-FEB-10 01.43.07.865272000 AM
    and systimestamp is 03-FEB-10 02.03.15.678084000 AM GMT-07:00. then the select query is returning 50.
    and when I query
    select systimestamp - InsertTmstmp from table1 ,, this is not returning any value . ( i saw in some sites this query returning values ).
    Thanks in advance

    May be like this?
    with t
    as
    select systimestamp - (systimestamp-1) dt from dual
    select dt,
           extract(day from dt)*24*60+extract(hour from dt)*60+extract(minute from dt)+extract(second from dt)/60 interval_in_min
      from t

  • Facing problem while calculating the difference between the two dates?

    Hi
    I am using this code to calculate the difference between the two dates :
    import java.util.Calendar;
    import java.util.*;
    public class DateDifferentExample
    public static void main(String[] args)
    // Creates two calendars instances
    Calendar cal1 = Calendar.getInstance();
    Calendar cal2 = Calendar.getInstance();
    // Set the date for both of the calendar instance
    cal1.set(2006, 12, 30);
    cal2.set(2007, 05, 03);
    // Get the represented date in milliseconds
    long milis1 = cal1.getTimeInMillis(); // getting error here
    long milis2 = cal2.getTimeInMillis(); // getting error here
    // Calculate difference in milliseconds
    long diff = milis2 - milis1;
    // Calculate difference in seconds
    long diffSeconds = diff / 1000;
    // Calculate difference in minutes
    long diffMinutes = diff / (60 * 1000);
    // Calculate difference in hours
    long diffHours = diff / (60 * 60 * 1000);
    // Calculate difference in days
    long diffDays = diff / (24 * 60 * 60 * 1000);
    System.out.println("In milliseconds: " + diff + " milliseconds.");
    System.out.println("In seconds: " + diffSeconds + " seconds.");
    System.out.println("In minutes: " + diffMinutes + " minutes.");
    System.out.println("In hours: " + diffHours + " hours.");
    System.out.println("In days: " + diffDays + " days.");
    but i am getting this error :
    The method getTimeInMillis() from the type calendar is not visible
    Please suggest!!

    // Get the represented date in milliseconds
    long milis1 = cal1.getTime().getTime(); // getting error here
    long milis2 = cal2.getTime().getTime(); // getting error here Hope this works for you!!

  • Expression or Function as field in Object Type

    I am trying to use an expression or call a function as a return value for a field in an OBJECT TYPE.
    Here's the obj def:
    CREATE OR REPLACE TYPE OUTAGE_REPEAT_CALL_T2 AS OBJECT (
         INITCALL_TS      DATE,
         LASTCALL_TS      DATE,
         CALL_SRC      CHAR(8),
         ELAPSED_TIME     NUMBER,
         REP_ID           CHAR(8),
         CALL_CNT      NUMBER(3)
    The ELAPSED_TIME field should be the differnece in minutes from the LASTCALL_TS and SYSDATE...
    I'm not sure how to select into this OBJECT to get my result...
    Sample table and data:
    SQL> desc oms.outage_repeat_call
    Name Null? Type
    ACCT NOT NULL NUMBER(10)
    INITCALL_TS NOT NULL DATE
    LASTCALL_TS NOT NULL DATE
    CALL_CNT NOT NULL NUMBER(3)
    CALL_SRC NOT NULL CHAR(8)
    REP_ID NOT NULL CHAR(8)
    The ELAPSED_TIME is not part of the underlying table..
    sample data from tbl:
    ACCT INITCALL_ LASTCALL_ CALL_CNT CALL_SRC REP_ID
    123456 02-JAN-02 02-JAN-02 1 CBIS MJB2302
    I want to have this as a result:
    INITCALL_ LASTCALL_ CALL_SRC ELAPSED_TIME REP_ID CALL_CNT
    02-JAN-02 02-JAN-02 CBIS 9997 MJB2302 1
    But by doing a select from the OBJECT TYPE:
    i.e.
    SELECT OUTAGE_REPEAT_CALL_T2(     ORPC.INITCALL_TS,
                        ORPC.LASTCALL_TS,
    ORPC.CALL_SRC,
                        'expression or func' AS ELAPSED_TIME,
    ORPC.REP_ID,
    ORPC.CALL_CNT)
    FROM
    OMS.OUTAGE_REPEAT_CALL ORPC
    WHERE
    ORPC.ACCT=123456;
    I am using DBMS_XMLQUERY to eventually get this:
    <?xml version = '1.0'?>
    <ROWSET>
    <ROW num="1">
    <INITCALL_TS>1/2/2002 12:45:0</INITCALL_TS>
    <LASTCALL_TS>1/2/2002 12:45:0</LASTCALL_TS>
    <CALL_SRC>CBIS </CALL_SRC>
    <ELAPSED_TIME>10009</ELAPSED_TIME>
    <REP_ID>MJB2302 </REP_ID>
    <CALL_CNT>1</CALL_CNT>
    </ROW>
    </ROWSET>
    Here's the real query... this OBJECT TYPE is embedded as an attribute of another OBJECT TYPE def.
              sQuery := 'SELECT '
                   || iNumAcct || ' AS NUMACCT,
                   SITE_T(S.ACCT,
                        S.SITE,
                        S.PHONE,
                        S.CUST_NM,
                        S.MED_IND,
                        S.MAC_IND,
                        S.HPP_IND,
                        S.STREET,
                        S.CITY,
                        S.STATE,
                        S.ZIP,
                        S.EUC,
                        S.STATUS,
                        S.AGR_TYP,
                        S.PRICE_SCHED,
                        S.OL_IND,
                        S.TRANS_IND,
                        S.CIRCUIT,
                        S.SUBSTATION,
                        S.OP_CENTER,
                        OUTAGE_STATUS_T(O.OUT_ID,
                             O.OUT_STATUS,
                             O.PO_DEV,
                             O.DEV_TYP,
                             O.CREW,
                             O.ETOR_TS,
                             O.TRBL_CD,
                             O.FIRST_RPT_TS,
                             O.END_TS,
                             O.CUST_CNT,
                             O.O_CALL_CNT,
                             OUTAGE_REPEAT_CALL_T(ORC.INITCALL_TS,
                                  ORC.LASTCALL_TS,
                                  ORC.CALL_SRC,
                                  ORC.REP_ID,
                                  ORC.CALL_CNT),
                             LIGHT_REPEAT_CALL_T(LRC.INITCALL_TS,
                                  LRC.LASTCALL_TS,
                                  LRC.CALL_SRC,
                                  LRC.REP_ID,
                                  LRC.CALL_CNT)
                             ) AS OUTCUST
                   FROM
                   OMS.SITE S,
                   OMS.OUTAGE O,
                   OMS.OUTAGE_REPEAT_CALL ORC,
                   OMS.LIGHT_REPEAT_CALL LRC,
                   OMS.OUTAGE_TRANSFORMER OT
                   WHERE
                   S.ACCT = ' || pi_acctNum || ' AND
                   S.TRNFRMR_ID = OT.TRNFRMR_ID(+) AND
                   OT.OUT_ID = O.OUT_ID(+) AND
                   S.ACCT = ORC.ACCT(+) AND                         
                   S.ACCT = LRC.ACCT(+)';
    I know this may sound confusing...but I apprecitate anyone's/everyone's suggestions!
    MJB
    DUKEPOWER CO.

    yes... here's the function that I also used as the expression...
    FUNCTION uf_minutesDiff(pi_beginDte IN VARCHAR2, pi_endDte IN VARCHAR2) RETURN NUMBER
    ||     FUNC name: uf_minutesDiff
    ||     purpose: this function accepts A BEGINNING DATE AND ENDING DATE AND
    ||               RETURNS THE DIFFERENCE IN MINUTES
    ||
    ||     date:     12/19/2001
    ||     author: Mark J Brooks
    ||
    ||     history:
    ||
    ||
    IS
         iMinutes     NUMBER;
    /*      LINE 280          */
    BEGIN
         select (to_date(pi_endDte,'DD-MON-YYYY:HH24:MI') -
              to_date(pi_beginDte,'DD-MON-YYYY:HH24:MI'))*24*60
              INTO iMinutes from dual;
         IF iMinutes = 0
         THEN
              iMinutes := 1;
         END IF;
         RETURN iMinutes;
    END uf_minutesDiff;
    I also just used:
    SQL> SELECT OUTAGE_REPEAT_CALL_T2( ORPC.INITCALL_TS,
    2 ORPC.LASTCALL_TS,
    3 ORPC.CALL_SRC,
    4 (ORPC.LASTCALL_TS - SYSDATE) AS ELAPSED_TIME,
    5 ORPC.REP_ID,
    6 ORPC.CALL_CNT)
    7 FROM
    8 OMS.OUTAGE_REPEAT_CALL ORPC
    9 WHERE
    10 ORPC.ACCT=123456;
    (ORPC.LASTCALL_TS - SYSDATE) AS ELAPSED_TIME,
    ERROR at line 4:
    ORA-00907: missing right parenthesis
    with and without the parens
    tx

Maybe you are looking for