Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Compare concatenated string with current timestamp

LukSkyWalkerMay 18 2021

Hello,
Environment info:
- DB version: 11.2.0.2.0

I have a table with column (VARCHAR2). In this column there are: date + time + some information. For example:
05/17/2021 12:53:56 Some string.

I would like to display rows that are not older than 30 min for example.
Lets say that I want to compare results of this two queries:
SELECT TO_CHAR(SYSDATE - INTERVAL '30' minute(1), 'MM/DD/YYYY HH24:MI:SS') FROM dual;
05/18/2021 10:53:15
SELECT SUBSTR(test_string, 0, 19) FROM test_table WHERE id = 10;
05/17/2021 12:53:53

I'm stuck. I tried few different approach. For example:
SELECT * FROM test_table WHERE TO_DATE(SUBSTR(test_string, 0, 19), 'MM/DD/YYYY HH24:MI:SS') >=TO_CHAR(SYSDATE - INTERVAL '30' minute(1), 'MM/DD/YYYY HH24:MI:SS') ;
Thank you in advance for suggestions.
Lukas

This post has been answered by Paulzip on May 18 2021
Jump to Answer
Comments
Post Details
Added on May 18 2021
3 comments
1,091 views