Subtract  timestamps

Hi,
it's about comparing timestamps by minutes. (ts1-ts2=? minutes). i.e.
i need to get the difference between two vars of type oracle.jbo.domain.Timestamp expressed in minutes. (some equivalent to oracle's "INTERVAL 'NNN' minute")
can't find the hint at ...
Thanks

You could use timestampValue() (inherited from oracle.sql.TIMESTAMP) and then use [url http://stackoverflow.com/questions/582278/how-to-calculate-the-difference-between-two-java-java-sql-timestamps]this technique
Not tested, just put together with the help of Google.

Similar Messages

  • Initializing INTERVAL data type

    I have a situation in which I want to keep track of the amount of time it takes to perform a task that it comprised of a number of steps. I need to get the amount of time to perform each task by subtracting the stop and start times; then these need to be added to a running total to track the total time to perform the task. My PL/SQL code looks something like this:DECLARE
      start TIMESTAMP;
      stop TIMESTAMP;
      task_time INTERVAL DAY TO SECOND;
      total_time INTERVAL DAY TO SECOND;
    BEGIN
      total_time := <an initial value (0)>;      -- How is this done?
      FOR i IN 1 .. <some upper limit> LOOP
        start := <some date and time>;
        stop := <some other date and time later than start>;
        task_time := stop - start;    -- Subtracting TIMESTAMPs results in an INTERVAL data type
        total_time := total_time + task_time;    -- Adding two INTERVALS results in an INTERVAL data type
      END LOOP;
    END;My question, as noted in the code is how do you initialize an INTERVAL data type?
    I have tried "total_time := 0" but I get a compile error because the types are not compatible. I have also tried setting it to "TO_DATE('00:00','hh24:mi')" but this also results in a type compatibility issue.
    Should I be approaching the problem in another way completely?

    Nothing could be simpler:
    declare
    v_interval interval day to second;
    begin
    v_interval := interval '0' hour;
    dbms_output.put_line(v_interval);
    end;

  • Subtract operation is not permitted on TIMESTAMP, INTEGER operand(s)

    I am running into a weird problem I have defined a formula in RPD to calculate Length of service. When I bring this column in with any other fact column it gives me error : Subtract operation is not permitted on TIMESTAMP, INTEGER operand(s)
    But if I define same calculation in answers using edit formula column it works just fine. I need to define it in rpd for the column to be present for ad-hoc. Where is my mistake?
    Answers definition: case when "Employment Events (Previous)"."Hire Date#1"> ifnull("Employment Events (Previous)"."Term Date", "Employment Events (Previous)"."Hire Date#1") then cast(Floor(case when "Employment Events (Previous)"."Hire Date#1"> ifnull("Employment Events (Previous)"."Term Date", "Employment Events (Previous)"."Hire Date#1") then case when "Employment Events (Previous)"."Hire Date#1" is not null then TIMESTAMPDIFF(SQL_TSI_MONTH, "Employment Events (Previous)"."Hire Date#1",CURRENT_DATE) ELSE NULL END ELSE NULL END /12) as char)||' year(s) '||cast(Mod(case when "Employment Events (Previous)"."Hire Date#1"> ifnull("Employment Events (Previous)"."Term Date", "Employment Events (Previous)"."Hire Date#1") then case when "Employment Events (Previous)"."Hire Date#1" is not null then TIMESTAMPDIFF(SQL_TSI_MONTH, "Employment Events (Previous)"."Hire Date#1",CURRENT_DATE) ELSE NULL END ELSE NULL END,12) as char)||' month(s)' else null end
    RPD: case when "Core"."Fact - Employment Events"."Hire Date" >IfNull( "Core"."Fact - Employment Events"."Term Date", "Core"."Fact - Employment Events"."Hire Date"-1) then
    cast(Floor(case when "Core"."Fact - Employment Events"."Hire Date" >IfNull( "Core"."Fact - Employment Events"."Term Date", "Core"."Fact - Employment Events"."Hire Date"-1) then
    case when "Core"."Fact - Employment Events"."Hire Date" is not null then TIMESTAMPDIFF( SQL_TSI_MONTH , "Core"."Fact - Employment Events"."Hire Date" , CURRENT_DATE) else null
    end
    else null
    END/12) as char)||' year(s) '||cast(Modcase when "Core"."Fact - Employment Events"."Hire Date" >IfNull( "Core"."Fact - Employment Events"."Term Date", "Core"."Fact - Employment Events"."Hire Date"-1) then
    case when "Core"."Fact - Employment Events"."Hire Date" is not null then TIMESTAMPDIFF( SQL_TSI_MONTH , "Core"."Fact - Employment Events"."Hire Date" , CURRENT_DATE) else null
    end
    else null
    END ,12) as char)||' month(s)'
    else null end
    Please Help!

    try this out :-
    case when "Core"."Fact - Employment Events"."Hire Date" >IfNull( "Core"."Fact - Employment Events"."Term Date", TIMESTAMPADD(SQL_TSI_DAY, -1, "Core"."Fact - Employment Events"."Hire Date"))
    then
    cast(Floor(case when "Core"."Fact - Employment Events"."Hire Date" >IfNull( "Core"."Fact - Employment Events"."Term Date", TIMESTAMPADD(SQL_TSI_DAY, -1, "Core"."Fact - Employment Events"."Hire Date")) then
    case when "Core"."Fact - Employment Events"."Hire Date" is not null then TIMESTAMPDIFF( SQL_TSI_MONTH , "Core"."Fact - Employment Events"."Hire Date" , CURRENT_DATE) else null
    end
    else null
    END
    /12) as char)||' year(s) '||cast(Modcase when "Core"."Fact - Employment Events"."Hire Date" >IfNull( "Core"."Fact - Employment Events"."Term Date", TIMESTAMPADD(SQL_TSI_DAY, -1, "Core"."Fact - Employment Events"."Hire Date")) then
    case when "Core"."Fact - Employment Events"."Hire Date" is not null then TIMESTAMPDIFF( SQL_TSI_MONTH , "Core"."Fact - Employment Events"."Hire Date" , CURRENT_DATE) else null
    end
    else null
    END ,12) as char)||' month(s)'
    else null end

  • Subtracting two timestamps and showing the number of hours between them.

    Hello Folks,
    What I have is two tables, each of them has a timestamp column. I want to do a select with a join that will show a column with the number of hours between the two times.
    (I have added the columns as timestamp(0) since I have no need for the decimals)
    Here's what I have:
    table one name: conc_test
    table one info:
    P_DATE-------JOB_NO-----MIX---POUR_NO----AMB_T---CONC_T--SLUMP---AIR---DENSITY---CYL_CAST_TIME
    09-MAR-10---9-12-796-----80----100309A------2.5--------16----------135------2.5----2501-------09-MAR-10 10.00.00 AM
    table two name: rls_break
    table two info:
    JOB_NO----POUR_NO-----CYL_ID----SPEC_STR---STR----MIX---BREAK_D_T
    9-12-796---100309A----100309A1------20-----------27-----80----10-MAR-10 07.15.00 AM
    (I put the --- between the columns so it would be more legible for forum reading, fyi)
    This is what I was trying to do:
    select
    rls_break.cyl_id "Cylinder ID",
    rls_break.mix "Mix",
    trunc(rls_break.break_d_t-conc_test.cyl_cast_time) "Age",
    rls_break.spec_str "Specified Strength",
    rls_break.str "Specimen Strength"
    from rls_break inner join conc_test on rls_break.pour_no = conc_test.pour_no
    where pour_no = '100309A';
    I want the "Age" column to show the total number of hours between the cast time (column cyl_cast_time from conc_test) and the break time (column break_d_t from rls_break)
    Thank's for any and all help.

    (I put the --- between the columns so it would be more legible for forum reading, fyi)Please put the tag before and after your examples.
    See: http://forums.oracle.com/forums/help.jspa for more information reagarding tags. (scroll a bit down)
    I want the "Age" column to show the total number of hours between the cast time (column cyl_cast_time from conc_test) and the break time (column
    break_d_t from rls_break)
    Do a search on 'NUMTODSINTERVAL' or 'time difference' on this forum, you'll find many related examples.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How do I use "touch -t" to shift a batch of JPG timestamps by one hour?

    I'm trying to use "touch -t" to shift a batch of JPG created/modified timestamps by one hour to fix a time zone error. Is this possible?
    (I don't want to have to manually go to every file, and enter its current timestamp all the same way except for the month.)
    By the way, does using the "touch" command have the same JPG lossy effect as saving the file again?

    picky picky picky
    So you write a script that uses stat to get the current modification time and then add 60 minutes to it, with the date command, then then use that with touch against the file. Nothing to it
    #!/bin/sh
    find starting.directory -name "*.jpg" | while read file
    do
    ls -l "$file"
    mtimeinsec=$(stat -f %m "$file")
    mtimeplus_1H_in_touchfmt=$(date -j -r $mtimeinsec -v +1H +%G%m%d%H%M.%S)
    /usr/bin/touch -t $mtimeplus_1H_in_touchfmt "$file"
    ls -l "$file"
    done
    I've added an hour to the modification time. If you want to subtract an hour the +1H to -1H
    If you want to use shell wildcard selection modify the loop to be something like
    #!/bin/sh
    for file in *.jpg
    do
    ... the guts of the above while loop ...
    done
    If you just want to provide a list of files, you can change the *.jpg to a list of files. JUST BE CAREFUL OF SPACES IN FILE NAMES and directories
    If you want a drag and drop application, you can do that with some additional changes and either using Applications -> Automator with the "Run Shell Command" or using Platypus (free download, and a very nice utility). The script would change to:
    #!/bin/sh
    for file in "$@"
    do
    ... the guts of the above while loop ...
    done
    I have tested the very first script. I am fairly confident my 2nd to examples are right, but they are untested, so your mileage may vary.

  • "scan from string" to timestamp doesn't work for 18:00:00 (6PM)

    I just found a strange issue in LabVIEW.  I hope I'm doing something silly, but I just may have found an unusual bug.
    run the snippet below with the following for the input string: 03:00:00,18:00:00,17:00:00
    Time converts fine for just about any other time EXCEPT 18:00:00 (6 PM) for which it is returned as 00:00:00 (midnight). If you even add a second to it (18:00:01) you get back the expected result.
    Here's hoping I'm not loosing my mind
    Matt Holt
    Certified LabVIEW Architect
    Solved!
    Go to Solution.
    Attachments:
    TimeParseBug.vi ‏11 KB

    As annoying as it may seem, this exact scenario is an abuse of the timestamp. A timestamp is meant to be used for absolute times. And that includes a date. As Ravens Fan already pointed out, the 0 seconds since January 1, 1904 GMT is used in all timestamp display routines to mean the canonical invalid timestamp and hence the timestamp control displays the default string indicating the actual date/time format rather than a specific date/time.
    If you need an absolute timestamp, for instance because you do want to have a local time indication, although the date is not relevant, adding an offset of 86400 to all values would fix it once and for all. Now the timezone offset can't cause the timestamp to reach 0 ever, even if you reside west of GMT, and it will be fine (until you start to do timestamp arithmetic that involves subtraction of relative timespans, then you would have to make the offset big enough that this will never get an issue). The current date would serve as a nice offset for that, which would be MattH's last suggestion. Nice to see that the Scan from String routine actually does use the passed in timestamp as default value and only replaces the values it is configured to parse.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Add or subtract minutes from any time of day

    Hello!
    The problem I'm having is that add or subtract minutes related
    to a time stamp like e.g.
    + (plus)
    17:21 timestamp
    minutes to add +80
    result -> 18:41
    - (minus)
    17:21 timestamp
    minutes to subtract -20
    result -> 17:01
    Is any function module existing for such
    cases. What would you recommend to me to
    solve the problem to get really reliable
    time.
    THX
    ilhan ertas

    Hi Ilhan,
    as long as you don't leave the limits of a day (i.e. time getting below zero or above 24 hours), ABAP time calculations will get correct results. Type t (time) fields in expressions involving numeric data types are internally converted into the amount of seconds.
    So you can  add minutes by multiplying by 60 (second per minute) first.
    In a type T field 17:21 is represented internally as 172100. Add 4800 (80 minutes times 60 seconds) will result (internally) to 17 * 60 * 60 + 21 * 60 + 4800 = 67260. And this will be converted to time format 184100.
    See also this SAP online help:
    <a href="http://help.sap.com/saphelp_erp2005vp/helpdata/en/fc/eb334a358411d1829f0000e829fbfe/content.htm">Date and Time Calculations</a>
    Regards,
    Clemens

  • JSTL Timestamp problem

    I want to subtract current Timestamp from other Timestamp which is from Database, but follwing error occured
    org.apache.jasper.JasperException: /jstl_online_user.jsp(18,2) The function Timestamp must be used with a prefix when a default namespace is not specified
         org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
         org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
         org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:150)
         org.apache.jasper.compiler.Validator$1FVVisitor.visit(Validator.java:1229)
         org.apache.jasper.compiler.ELNode$Function.accept(ELNode.java:122)
         org.apache.jasper.compiler.ELNode$Nodes.visit(ELNode.java:193)
         org.apache.jasper.compiler.ELNode$Visitor.visit(ELNode.java:234)My code
    <%@ page import="java.sql.*,javax.sql.*,javax.naming.*"  isELIgnored ="false"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
    <sql:query var="rs_online" dataSource="helpdeskJNDIRef">
      Select u.user_id,user_ip,user_timestamp,user_what_action,user_what_arg1,user_name,user_display_name from user u , whos_online w where u.user_id=w.user_id
    </sql:query>
    <html>
      <head>
        <title>DB Test</title>
      </head>
      <body>
        <h2>Results</h2>
         <c:out value="${1 + 2 + 3}" />
        <c:forEach var="row" items="${rs.rows}">
              Text Message: <c:out value="${i.user_name}"/><br>
              <c:set var="logged" value="${(new java.sql.Timestamp(new java.util.Date().getTime())).getTime() - row.user_timestamp}" scope="page" />
                <c:out value="${logged}" />
        </c:forEach>
      </body>
    </html>Edited by: sagar_birari on 7 Jun, 2008 12:02 PM

    EL is not a scripting language, just an Expression Language, so you can't create timestamps with it.
    You probably shouldn't be doing this logic in the JSP anyway. Try moving the logic to beans. The code might look something like this:
    <%@ page isELIgnored ="false"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <!-- Create a bean then controls getting the user(s) from the database -->
    <jsp:useBean id="userLog" class="login.UserLog" scope="request" scope="page">
      <!-- Use a public void setUserName(String) method to set the w.user_id. 
           This method may execute the SQL and store results
      -->
      <jsp:setProperty name="user" property="userName" value="w.user_id"/>
    </jsp:useBean>
    <!-- Get a List<User> of all the logged in users that match the name given previously.
         If the setUserName method didn't execute the SQL, then the method
         public List getAllUsers(void) method this line calls should.
    -->
    <c:set var="usersLoggedIn" value="${userLog.allUsers}" scope="page" />
    <html>
      <head>
        <title>DB Test</title>
      </head>
      <body>
        <h2>Results</h2>
         <c:out value="${1 + 2 + 3}" />
        <!-- Iterate over the List<User> of users.  Objects in the list are of another bean type (login.User) -->
        <c:forEach var="user" items="${usersLoggedIn}">
              <!-- Call login.User#public String getUserName(void) method -->
              Text Message: <c:out value="${user.userName}"/><br>
              <!-- Call login.User#public String getLoggedTime(void) method which takes the current timestamp
                   and subtracts the time the user logged in, and converts it back to a String for display
              -->
                <c:out value="${user.loggedTime}" />
        </c:forEach>
      </body>
    </html>Of course, you could try doing the timestamp math in a scriptlet <% ... %> and storing the value in the pageContext.

  • How to get timestamp to start at zero hours?

    Hi.
    I'm building a software that logs values to excel.
    The user can enter how long the test should run for, and the time elapsed should be set as a string in [hh:mm:ss]
    The only problem is that the TimeStamp starts at 01:00:00 (beacuase of the 1904-issue i guess). How can I get the counter to start at 00:00:00, or maybe subtract the one hour in the begining so it starts at zero.
    If you run the VI you'll understand what I mean.
    Thanks!
    Is my avatar the dog from the fraggle rock?
    Solved!
    Go to Solution.
    Attachments:
    forum_program1.vi ‏26 KB

    Hi auto,
    you have to use relative time instead of absolute time - see attachment...
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome
    Attachments:
    forum_program1.vi ‏27 KB

  • PSE 10 Organizer on Mac shows wrong timestamps and changes timestamps

    Just installed PSE 10 on my Mac (OSX 10.6.8) performed an update to the raw converter (though I am NOT using raw files)
    All photos that I add to the catalog show a time stamp of 1hr before the photo was taken.  If I check the actual metatdata it shows correct for most of the fields.
    Exif data before adding to organizer: (using Exif Viewer 2.7.1)
    Image Created:          2012:03:21 07:27:26
    Image Generated:          2012:03:21 07:27:26
              Image Digitized:          2012:03:21 07:27:26
    I drag it into Organizer and it shows as being 3/21/2012 6:27am
    The exif data still shows properly in Exif Viewer.
    Ok, I can deal with that, it is very odd, but since it isn't changing the exif data it is somewhat ok. 
    Until....
    Now, I right click on the image and say open with Photoshop Elements Editor and immediately the time changes on the organizer screen to be one hour earlier from shown: 5:27am.
    PSE Editor File info shows the Created and Modified times on the desciption tab as 7:27, but on the Camera Data tab shows 3/21/2012 – 6:27 AM (the time organizer showed before I said to open editor)
    now Exif Viewer says:
    Image Generated:          2012:03:21 06:27:26
              Image Digitized:          2012:03:21 07:27:26
    close editor, and organizer is still saying the time is 5:27am
    Close organizer, open again, still shows 5:27am, exif data still shows:
    Image Generated:          2012:03:21 06:27:26
              Image Digitized:          2012:03:21 07:27:26
    I can repeat the open in editor and it again subtracts an hour from the time shown, and from the Image Generated exif data field.
    It appears that the organizer updates the timestamp when you say open in editor, and then sees that the timestamp changed and shows its 1hr subtracted time.
    Definate bug! It happens with JPG files from 3 different cameras (2 canon, 1 nikon) does not appear to happen with MP4 files from Flip.  but does happen with MOV files from at least 1 of the canon cameras.
    Any ideas?  I haven't found the place to report bugs for PSE10 yet.
    -Mike

    found a place to report the problem:
    http://feedback.photoshop.com/photoshop_family/topics/pse_10_organizer_on_mac_shows_wrong_ timestamps_and_changes_timestamps
    or: http://gsfn.us/t/2qfku
    If you have the same problem, please go there and click that you also have the problem to increase their awareness of the issue.

  • Can we import a timestamp column in DIAdem

    I have a 2 channels with time information - one in string format and the other in timestamp format.  It seems that when I try to open my TDM file, DIAdem gets stuck.  I'm sure that its because I can't have string or timestamp information in a TDM file.  If that is the case then how do I import my time?  Thanks.
    --cj

    Hi cmiranda,
    Actually, you can have both string and date/time channels in a TDM file and in DIAdem.  So, I'm guessing the way you're writing your TDM file is suspect if DIAdem is hanging trying to import it.  What happens when you try to load that TDM file back into LabVIEW?
    The one goofy thing about this with LabVIEW 7.x and DIAdem 9.x is that LabVIEW saves the date/time values as the time in Greenwich, England (GMT), whereas DIAdem expects time to be saved as the local time.  So you either have to add on the number of seconds of time shift you have with GMT in LabVIEW prior to saving, or you have to add on those seconds after you've loaded the date/time channels into DIAdem.
    I'm including below an example of how to do the former-- save date/time channels in LabVIEW which can be read back perfectly in DIAdem.  Note, though, that this means these same value read back into LabVIEW will be interpreted incorrectly, so you have to make a fundamental choice to make DIAdem or LabVIEW happy and run a quick addition/subtraction in the other application.  We are indeed working to make this less irksome.
    Feel free to send in your VI that is creating the TDM file,
    Brad Turpin
    DIAdem Product Support Engineer,
    National Instruments
    Attachments:
    Save DIAdem DateTime.llb ‏232 KB

  • Using TRUNC in timestamps

    Sir,
    As you know we were using TRUNC function in DATE datatype. But I want to use it with TIMESTAMP datatypes. For example:
    select trunc(systimestamp,'hh24:mi:ss') from dual;
    The main idea to get some part of given timestamp without using type conversions (i.e. TO_CHAR).
    Note that this is useful when you want to ADD or Subtract the time side from timestamp with interval values and comparing them to another timestamps fields or values.
    Thank you in advance.

    Trunc is not working in 9i
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.1.0 - Production
    SQL> SELECT current_timestamp - TRUNC (current_timestamp) time
    2 FROM dual
    3 /
    SELECT current_timestamp - TRUNC (current_timestamp) time
    ERROR at line 1:
    ORA-00932: inconsistent datatypes: expected NUMBER got TIMESTAMP
    SQL>
    But in 10g...
    Personal Oracle Database 10g Release 10.1.0.2.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL> SELECT current_timestamp - TRUNC (current_timestamp) time
    2 FROM dual;
    TIME
    +000000000 14:53:04.941000
    SQL>
    Why?

  • How do you begin waveform timestamps at zero?

    I am new to labview, writing my first program.  I am collecting 1000 Hz temperature data, the sample rate of which can be changed on the fly.  I have 12 channels of data, so I get an array of 12 waveforms.  I wanted to get the timing data from just one waveform, so I was able to use the "get waveform time array" vi to collect that information, but it displays the real time (number of seconds since 1903 etc), and I want my timing to start at zero when I begin the vi.  It needs to be accurate to the millisecond.  I thought that I could just subtract the time (in seconds since 1903) of when the vi started from each element of the array and I would then start at zero, but there appears to be some kind of timing error or lag time and the results I get always start the time somewhere between 1.000 and 5.000 seconds, (something like 1.458, etc), which is unacceptable.  I can easily fix the problem in Excel, but if anybody knows a better way around this problem, the help would be greatly appreciated.
    Attachments:
    Welding Program Variable Rate.vi ‏412 KB

    rgehmlich,
    I think the reason you're having trouble getting the timestamp to start at 0 is because the acquisition and the Get Date/Time in Seconds.vi are not happening at the same time. I think the system time is being read at the start of the program, and then the code goes through creating or opening the file, setting up the task, and doing the acquisition and all this probably takes between 1 and 5 seconds (with selecting the file to be opened). What I think would work better is to take the time information of the first waveform from the first iteration of the while loop and subtract that value instead of the Get Date/Time in Seconds value. I've modified your code to do this (and I took out the daq code and replaced it with an express VI since I don't have a daq card in my computer right now) and the timestamps start at 0 for me. Take a look and see if it helps.
    Tyler S.
    Attachments:
    Welding Program Variable Rate[2].vi ‏470 KB

  • Timezone, Timestamp Arithmetics

    Pl. throw more light on Timestamp and Timezone arithmetics.
    I need to subtract SessionTimezone from the Current_timestamp.
    If I try to execute the statement "Select Current_Timestamp - SessionTimezone", I get error "ORA - 001722: Invalid Number".
    How to accomplish my requirement?
    Is there any specific formatting required to perform Timestamp, Timezone arithmetics?

    Your select statement is failing because SessionTimezone is not a Timestamp. It is the offset between where you are and GMT (aka UTC). You should be able to do maths with two actual timestamps.
    Cheers, APC

  • How to use lag on timestamp

    Thanks..
    SQL> define TNAME='PATIENT_AUD'
    SQL> define CNAME='AUD_CREATED_TS'
    SQL> define MINGAP=10
    WITH aquery
    SQL> 2 AS (SELECT &cname after_gap
    ,LAG (&cname, 1, 0) OVER (ORDER BY &cname) before_gap
    FROM &tname)
    3 4 5 SELECT before_gap, after_gap, (after_gap - before_gap) delta
    FROM aquery
    6 7 WHERE before_gap != 0 AND after_gap - before_gap > &mingap;
    old 2: AS (SELECT &cname after_gap
    new 2: AS (SELECT AUD_CREATED_TS after_gap
    old 3: ,LAG (&cname, 1, 0) OVER (ORDER BY &cname) before_gap
    new 3: ,LAG (AUD_CREATED_TS, 1, 0) OVER (ORDER BY AUD_CREATED_TS) before_gap
    old 4: FROM &tname)
    new 4: FROM PATIENT_AUD)
    old 7: WHERE before_gap != 0 AND after_gap - before_gap > &mingap
    new 7: WHERE before_gap != 0 AND after_gap - before_gap > 10
    ,LAG (AUD_CREATED_TS, 1, 0) OVER (ORDER BY AUD_CREATED_TS) before_gap
    ERROR at line 3:
    ORA-00932: inconsistent datatypes: expected TIMESTAMP WITH TIME ZONE got NUMBER
    SQL>

    The LAG "(&cname, 1, &cname-(1/24/60))" was exactly what I needed in some transaction analysis code I am working on. Thanks 807511
    If it helps anyone this is what I ended up with :-
    Select a few fields from the debug table
    , get the end_time from the previous record
    , subtract the current record start time from the end time of the prior record
    SELECT transaction_type
    ,      trans_time
    ,      validation_time
    ,      transaction_start_time
    ,      transaction_end_time
    ,      LAG(transaction_end_time, 1, transaction_start_time - (1/24/60/1000))
               OVER ( ORDER BY transaction_start_time ) AS prior_transaction_end_time
    ,      transaction_start_time -
           LAG(transaction_end_time, 1, transaction_start_time - (1/24/60/1000))
               OVER ( ORDER BY transaction_start_time ) AS transaction_lag
    FROM debug_datasource_tmp_v
    WHERE transaction_type = 'PONotification'
    ORDER BY 4;

Maybe you are looking for