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

Similar Messages

  • 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

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

  • 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

  • Data difference between DBA_HIST_SQLSTAT and DBA_HIST_ACTIVE_SESS_HISTORY

    HI,
    I ran a query on a database few times which had different execution plan (basically first I ran with index and later without index).
    I tried to cross verify the data from DBA_HIST_SQLSTAT and DBA_HIST_ACTIVE_SESS_HISTORY for that particular query and found there were two different SQL ID for same SQL statement. Ideally if execution plan changes then only the plan hash value or hash value changes but in this scenario we have two different SQL ID with different Plan hash value or hash value.
    I need to understand why do we have this data difference?
    ==================================================================================================
    SQL> select snap_id,instance_number,sample_time,session_id,module,sql_plan_hash_value from dba_hist_active_sess_history where sql_id='9zgyc24gzsgpz';
    SNAP_ID INSTANCE_NUMBER SAMPLE_TIME SESSION_ID MODULE SQL_PLAN_HASH_VALUE
    9478 2 07-JAN-11 13.09.11.540 503 SQL*Plus 2290340548
    9478 2 07-JAN-11 13.23.42.616 514 SQL*Plus 3778028574
    9478 2 07-JAN-11 13.25.12.735 514 SQL*Plus 3778028574
    9478 2 07-JAN-11 13.25.22.746 514 SQL*Plus 3778028574
    9478 2 07-JAN-11 13.25.32.759 514 SQL*Plus 3778028574
    9478 2 07-JAN-11 13.25.42.770 514 SQL*Plus 3778028574
    9478 2 07-JAN-11 13.25.52.782 514 SQL*Plus 3778028574
    9478 2 07-JAN-11 13.26.02.795 514 SQL*Plus 3778028574
    9478 2 07-JAN-11 13.26.12.811 514 SQL*Plus 3778028574
    9478 2 07-JAN-11 13.26.22.823 514 SQL*Plus 3778028574
    SQL> select snap_id,sql_id,plan_hash_value from dba_hist_sqlstat where sql_id='9zgyc24gzsgpz' ;
    SNAP_ID SQL_ID PLAN_HASH_VALUE
    9478 9zgyc24gzsgpz 2290340548
    ==================================================================================================
    Thanks
    Devendra

    Hi,
    DBA_HIST_ACTIVE_SESS_HISTORY is a sampling of the sampling already done in ASH, however data used for AWR "snapshots" is completely separate and works just like Statspack did, so it can capture all SQL in the shared pool at the time of the snapshot if you tell it to - it is not limited to just the SQL sampled by ASH. Also AWR does not capture every statement executed in the interval,even if the statement was not aged out from V$SQL.
    DBA_HIST_ACTIVE_SESS_HISTORY displays the history of the contents of the in-memory active session history of recent system activity, DBA_HIST_SQLSTAT displays historical information about SQL statistics
    Regards,
    Ugur

  • Get Date Difference between 2 date values as days

    Hi,
    How to get the difference between 2 dates in number of days format. Say if i need the difference between 2012-08-23 and 2012-08-20 as 3
    Please help..

    Hi,
    You can do it in XSLT since the dates are in ISO 8601 format...
    http://www.w3.org/TR/NOTE-datetime
    Here is a sample XSLT...
    <xsl:stylesheet  version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:fn="http://www.w3.org/2005/xpath-functions">
    <xsl:template match="/">
    <xsl:variable name="date1" select="xs:dateTime(/root/date1)"/>
    <xsl:variable name="date2" select="xs:dateTime(/root/date2)"/>
    <xsl:value-of select="fn:days-from-duration($date2 - $date1)"/>
    </xsl:template>
    </xsl:stylesheet>The above XSLT will result *4* for the following input...
    <root>
    <date1>2012-01-11T00:00:00.000-05:00</date1>
    <date2>2012-01-15T00:00:00.000-05:00</date2>
    </root>You can test this example here...
    http://xslttest.appspot.com/
    Hope this helps...
    Cheers,
    Vlad
    It is considered good etiquette to reward answerers with points (as "helpful" - 5 pts - or "correct" - 10pts)
    https://forums.oracle.com/forums/ann.jspa?annID=893

  • Date difference between Requsition apporval and Po approval in Oracle apps

    My requirement is that l need to get the number of date difference between requisition apporval date(requisition) and po approval date (purchase) excluding holidays how to do it ?
    Thanks in advance..

    One PO could be generated from multiple requisitions. In that case, which requisition would you like to consider?
    One requisition could be converted into multiple POs. In that case, which PO would you like to consider?
    Assuming, there is a one-to-one relationship between your POs and requisitions:
    Link a PO to the corresponding requisition by joining po_distributions_all.req_distribution_id with po_req_distributions_all.requisition_id
    Once you have found the 2 records, get the approved_date from po_headers_all and po_requisition_headers_all
    Then go to bom_calendar_dates for those dates and find the difference between seq_num. That is what you are looking for.
    Sandeep Gandhi

  • Query report with date difference.

    Hi Expert,
    I'm using below query to monitor unreleased checks. we have a policy that the holding period for unreleased check is 5 working days.
    SELECT T2.[CardCode], T2.[CardName], T0.[TransId], T0.[DueDate], T1.[Credit], T1.[U_DisBank], T4.[Name], DateDiff(dd,T0.[DueDate],GetDate()) As 'OverDue Days' FROM OJDT T0  INNER JOIN JDT1 T1 ON T0.TransId = T1.TransId  INNER JOIN OCRD T2 ON T1.ShortName = T2.CardCode  INNER JOIN "@HOFFICE"  T4 ON T1.U_Disbank = T4.Code WHERE T1.[Credit] !=0 AND  T0.[DueDate] >=[%0] AND  T0.[DueDate] <=[%1] AND  T1.[balduedeb]+T1.[balduecred] !=0 ORDER BY T4.[Name]
    However I would like to exclude weekends in computing date difference. Can you please help me modify my query code?
    Thanks,
    Arlmi2000

    Hi,
    A simple solution will be change DateDiff(dd,T0.DueDate,GetDate()) to DateDiff(dd,T0.DueDate,GetDate())*5/7+1
    This can cover all the weekends. If you need to be exact that including public holiday, the coding will be  longer.
    Thanks,
    Gordon

  • Date differences if one of the field not presenting

    Hi All,
    I have two attributes start date and end. I have created formula replacement variable.
    some  times one of the field coming as blank, in such acase system writing some garbage value but i need blank.
    How to resolve this issue.
    Reagrds,
    J B

    Hi,
    You can create a new formula in query designer with a condition such that date difference doesn't fall in the invalid value. If it that invalid value put the result as '0'.
    http://help.sap.com/saphelp_nw04/helpdata/en/23/17f13a2f160f28e10000000a114084/frameset.htm
    If the output is showing as '0' for the invalid values then in the query properties select the Display zeroes as Do Not Display Zeroes.
    http://help.sap.com/saphelp_nw04/helpdata/en/1e/99ea3bd7896f58e10000000a11402f/frameset.htm
    Hope this helps.........
    Rgs,
    Ravikanth.

  • Finding Date difference

    Hi,
    I want to find the duration of stock in quality.
    Is there any direct formula available to calculate the date difference.
    Or I need to create a variable for this.
    Thanks, Jeetu

    Hi,
    You can also calculate date difference at query level using replacement path variables.
    Check this link:-
    http://www.sd-solutions.com/documents/SDS_BW_Replacement%20Path%20Variables.html
    regards,
    Pruthvi R

  • Date Difference Calculation in BW3.5

    Hi
    We are calculating date differences between 2 dates i.e. Delivery Date - System Date.For System date we used variable exit to derive the value.But when we create CKF on Delivery Date,we necessary have to keep date field in Drilldown(in rows).But reports needs to give Overview while including date field in rows removes the granularity.
    Is thier any other way we can handle this situation.
    Regards
    Praveen

    You have to put ur delivery date in Rows if u r doing the Formula variable with replacement path. There is no option.
    Khaja

  • Calculate date differences in consecutive rows and generate a sequence

    Hi Guys,
    I am trying to implement one scenario where in i need to compare the date differences for consecutive rows and generate a sequence against that.
    this is the table schema:
    create table temp
    id int identity(1,1),
    emp_id int,
    time datetime
    insert into temp 
    values
    (1, '2011-02-20 12:30:00.000'),
    (1, '2011-02-20 12:32:34.172'),
    (1, '2011-02-20 12:32:34.172'),
    (1, '2011-02-20 12:43:21.004'),
    (1, '2011-02-20 12:46:39.745'),
    (2, '2011-02-20 12:48:06.004'),
    (2, '2011-02-20 12:48:06.004'),
    (2, '2011-02-20 12:53:07.733'),
    (2, '2011-02-20 12:55:30.295');
    now, I want to compare the first date-time with the second and so on. now if the date-time difference is same for two consecutive rows then the sequence should  increment by 1 otherwise the sequence again will start from '00' for any unique date-time.
    This sequence number should start from '00' from each employee.
    I want the output to be like this
    ID emp_id
    time    
    sequence
    1 1 2011-02-20 12:30:00.000
    00
    2  1 2011-02-20 12:32:34.172
    00
    3  1 2011-02-20 12:32:34.172
    01
    4  1 2011-02-20 12:32:34.172
    02
    5  1 2011-02-20 12:46:39.745
    00
    6  2 
    2011-02-20 12:48:06.004 00
    7  2 
    2011-02-20 12:48:07.003 00
    8  2 
    2011-02-20 12:48:07.003 01
    9  2 
    2011-02-20 12:46:39.745 00
    Please revert as soon as possible as this is a bit urgent.
    Thank You in Advance. :)

    create table temp
    (id int identity(1,1),
     emp_id int,
     time datetime
    insert into temp values
    (1, '20110220 12:30:00.000'),
    (1, '20110220 12:32:34.172'),
    (1, '20110220 12:32:34.172'),
    (1, '20110220 12:43:21.004'),
    (1, '20110220 12:46:39.745'),
    (2, '20110220 12:48:06.004'),
    (2, '20110220 12:48:06.004'),
    (2, '20110220 12:53:07.733'),
    (2, '20110220 12:55:30.295');
    go
    SELECT id, emp_id, time,
           dateadd(mcs, (row_number() OVER(PARTITION BY emp_id, time ORDER BY
    id) - 1) * 10,
                   convert(datetime2(5), time)) AS [Sequence]
    FROM   temp
    ORDER  BY id
    go
    DROP TABLE temp
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Row wise Date Difference

    Hi
    I have one column which contains Date field. and I want date difference between two rows like (1st row- 2nd row),(2st row- 3nd row) 3-4,4-5 like that.
    How I can get this
    Thanks
    Siddhartha P

    As for the minutes calculation it doesn't take Einstein to know that the number of minutes in a day = 24 (hours) * 60 (minutes)
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 1 as id, sysdate-10 as dt from dual union all
      2             select 2, sysdate-7.4 from dual union all
      3             select 3, sysdate-6.45 from dual union all
      4             select 4, sysdate-2.82 from dual union all
      5             select 5, sysdate from dual)
      6  -- END OF TEST DATA
      7  select id
      8        ,dt
      9        ,dt-lag(dt) over (order by id) as dt_diff_days
    10        ,(dt-lag(dt) over (order by id))*(24*60) as dt_diff_minutes
    11* from t
    SQL> /
            ID DT                  DT_DIFF_DAYS DT_DIFF_MINUTES
             1 30/11/2007 13:07:37
             2 03/12/2007 03:31:37          2.6            3744
             3 04/12/2007 02:19:37          .95            1368
             4 07/12/2007 17:26:49         3.63          5227.2
             5 10/12/2007 13:07:37         2.82          4060.8
    SQL>

  • Date difference in one column

    Hi all,
    I need the column DATEDIFFERENCE as per below
    Kindly help me out .
    How to perform on the same column .
    Regards, Subathra

    create table test (id varchar(10), createddate datetime, assigneddate datetime, resolveddate datetime)
    insert into test values ('SD1023','4/2/2014 10:02:00','4/2/2014 10:06:00','6/2/2014 20:06:03')
    insert into test values ('SD1023','4/2/2014 10:02:00','4/2/2014 10:20:01','6/2/2014 20:06:03')
    insert into test values ('SD1023','4/2/2014 10:02:00','4/2/2014 12:02:00','6/2/2014 20:06:03')
    insert into test values ('SD1023','4/2/2014 10:02:00','6/2/2014 20:06:03','6/2/2014 22:10:03')
    insert into test values ('SD10123','6/2/2014 20:06:03','6/2/2014 20:06:03','6/2/2014 23:06:06')
    insert into test values ('SD10123','6/2/2014 20:06:03','6/2/2014 21:06:04','6/2/2014 23:06:06')
    insert into test values ('SD10123','6/2/2014 20:06:03','6/2/2014 22:06:05','6/2/2014 23:06:06')
    insert into test values ('SD10123','6/2/2014 20:06:03','6/2/2014 23:06:06','6/2/2014 23:06:06')
    ;with mycte as (select *,row_number() Over(Partition by id Order by AssignedDate) rn1
    ,row_number() Over(Partition by id Order by AssignedDate DESC) rn2
    from test)
    ,mycte1 as (
    Select m0.id,m0.createddate,m0.assigneddate,m0.resolveddate,
    CASE WHEN m0.rn1=1 Then m0.createddate Else m1.assigneddate End as dt1,
    CASE WHEN m0.rn2=1 Then m0.resolveddate Else m0.assigneddate end as dt2
    from mycte m0 left join mycte m1 on m0.id=m1.id and m0.rn1=m1.rn1+1)
    select id,createddate,assigneddate,resolveddate
    ,datediff(second,dt1,dt2) as [Date Difference in seconds] from mycte1
    order by dt1
    drop table test

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

Maybe you are looking for