Skip to content
Advertisement

How do I get results from past 1 hour in sql

I have this query to get all caseids that are less than 10 chars and do not have a T in front from the past hour:

SELECT * 
FROM PICKDETAIL 
WHERE LENGTH(CASEID) <> 10 
  AND CASEID NOT LIKE 'T%' 
  AND TO_CHAR(editdate, 'hh24mi') > TO_CHAR(sysdate - 1/24, 'hh24mi');

But when I run this I will still get results from days ago.

What could I be doing wrong here?

Advertisement

Answer

Don’t convert to a string. Just use date comparisons:

SELECT pd.*
FROM PICKDETAIL pd
WHERE LENGTH(pd.CASEID) <> 10 AND
      pd.CASEID NOT LIKE 'T%' AND 
      pd.editdate > sysdate - 1/24;
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement