PS Query & SQL

 View Only
  • 1.  Elapsed Time / Timestamp Differences - Any (Easy) Expresssions?

    Posted 9 days ago

    Hi folks!

    I'm trying to determine elapsed time using the difference between two timestamps. This is the current expression I am using:

    (TO_TIMESTAMP(CAST((A.ENDDTTM) AS TIMESTAMP),'YYYY-MM-DD-HH24.MI.SS.FF') -  TO_TIMESTAMP(CAST((A.BEGINDTTM) AS TIMESTAMP),'YYYY-MM-DD-HH24.MI.SS.FF')) * 86400

    It works most of the time, but does fail on occasion, especially if the difference is too large.

    Was curious to know if anyone has anything better that works more reliably. Google has not been my friend, and AI has been equally unhelpful, so I figured I would consult RI (real intelligence).

    Thanks in advance!



    ------------------------------
    Mark Russom B.Sc. FLMI ACS
    Business Systems Lead
    McMaster University
    ------------------------------

    Message from the HEUG Marketplace:
    ------------------------------
    Find, Review, and Engage with Higher Education-focused solution providers, products, and services using the HEUG Marketplace.
    ------------------------------
    Alliance 2026 Recordings are coming soon!


  • 2.  RE: Elapsed Time / Timestamp Differences - Any (Easy) Expresssions?

    Posted 9 days ago

    Not sure if this will work but it has worked for us.  I take no credit for this...  Had someone help me with this.

     

    (TO_DATE(SUBSTR(A.ENDDTTM,1,16),'YYYY-MM-DD-HH24.MI') - TO_DATE(SUBSTR(A.BEGINDTTM,1,16),'YYYY-MM-DD-HH24.MI')) *24 *60

     

    This gives me the number of minutes a process runs....  You can change it for what you want.

     




    Alliance 2026 Recordings are coming soon!


  • 3.  RE: Elapsed Time / Timestamp Differences - Any (Easy) Expresssions?

    Posted 9 days ago

    I got this from Jeffie Brooks to break the time difference between 2 timestamps into  hours:minutes:seconds.   You likely can use datediff also.

     

    SUBSTR(ENDDTTM - BEGINDTTM,12,8)

     

     

     

     

    Thanks!

    Dana Pawlowicz

    Business Systems Analyst Sr - ERP

    Business Enterprise Systems and Technologies
    Digital Technology Solutions

    University of Cincinnati

    51 Goodman Dr.

    Cincinnati, Oh 45221

     

     




    Alliance 2026 Recordings are coming soon!


  • 4.  RE: Elapsed Time / Timestamp Differences - Any (Easy) Expresssions?

    Posted 8 days ago

    Hey Mark,

      I am assuming you're working in Oracle SQL (since PS query would reject the AS keyword).  In that case, you could use an inline view like

    SELECT
        EXTRACT(DAY FROM DIFF)*86400 + EXTRACT(HOUR FROM DIFF)*3600 + EXTRACT(MINUTE FROM DIFF)*60 + EXTRACT(SECOND FROM DIFF) "TIME_IN_SEC"
    FROM(
        SELECT
            (A.ENDDTTM - A.BEGINDTTM) "DIFF"
        FROM YOUR_RECORD A
        WHERE
           YOUR_WHERE_CLAUSE = TRUE
    )

    In a query expression you could use the same EXTRACT logic, you'd just have to subtract the timestamps in each one.



    ------------------------------
    Scott Nishizaki
    Connected Campus Community of Practice
    Developer/Analyst
    Azusa Pacific University
    ------------------------------

    Message from the HEUG Marketplace:
    ------------------------------
    Find, Review, and Engage with Higher Education-focused solution providers, products, and services using the HEUG Marketplace.
    ------------------------------

    Alliance 2026 Recordings are coming soon!


  • 5.  RE: Elapsed Time / Timestamp Differences - Any (Easy) Expresssions?

    Posted 8 days ago
    In PS Query, I use something similar to what Shareen posted to return the time in minutes.  This is the expression:
     
    (cast(to_timestamp(A.ENDDTTM, 'YYYY-MM-DD-HH24.MI.SS.FF') as date) - cast(to_timestamp(A.BEGINDTTM, 'YYYY-MM-DD-HH24.MI.SS.FF') as date)) *1440


    ------------------------------
    Ruby Nugent
    University of Michigan
    rubyn@umich.edu
    ------------------------------

    Alliance 2026 Recordings are coming soon!


  • 6.  RE: Elapsed Time / Timestamp Differences - Any (Easy) Expresssions?

    Posted 7 days ago

    Sorry, I am fully backward.  AS is allowed in Expressions but FROM isn't, so only the SQL part of my answer is relevant.



    ------------------------------
    Scott Nishizaki
    Connected Campus Community of Practice
    Developer/Analyst
    Azusa Pacific University
    ------------------------------

    Message from the HEUG Marketplace:
    ------------------------------
    Find, Review, and Engage with Higher Education-focused solution providers, products, and services using the HEUG Marketplace.
    ------------------------------

    Alliance 2026 Recordings are coming soon!


  • 7.  RE: Elapsed Time / Timestamp Differences - Any (Easy) Expresssions?

    Posted 7 days ago

    Thanks Shareen, Dana, Scott, and Ruby!

    I was able to get my query to behave using both Shareen's and Ruby's expressions, slightly tweaked to get me down to the seconds.

    Y'all are awesome!



    ------------------------------
    Mark Russom B.Sc. FLMI ACS
    Business Systems Lead
    McMaster University
    ------------------------------

    Message from the HEUG Marketplace:
    ------------------------------
    Find, Review, and Engage with Higher Education-focused solution providers, products, and services using the HEUG Marketplace.
    ------------------------------

    Alliance 2026 Recordings are coming soon!