-4

I have a table with the field ENTERED_ON (with both date and time value). I want to write a query that return records that have ENTERED_ON value that is past 2 hours comparing to current date time.

For example, if entered_on is 2014-05-06 11:00AM, and currently it's 2014-05-06 2:00PM, I would like to return all records that past the 2 hours when comparing to current date time.

zessx
  • 68,042
  • 28
  • 135
  • 158
rvpals
  • 177
  • 1
  • 3
  • 15
  • Shows the work you did so far. – Zangdak May 06 '14 at 14:43
  • 1
    http://stackoverflow.com/questions/14208958/select-data-from-date-range-between-two-dates duplicate? http://stackoverflow.com/questions/8079671/find-records-with-a-date-field-in-the-last-24-hours duplicate? – Dávid Szabó May 06 '14 at 14:43

1 Answers1

0

You can write query using INTERVAL. It will looks like

SELECT * FROM Table WHERE `ENTERED_ON` > DATE_ADD(NOW(), INTERVAL -2 HOUR)
galethil
  • 996
  • 8
  • 13
  • DATE_ADD doesn't work. Oracle said invalid identifier. – rvpals May 06 '14 at 15:04
  • @rvpals - that's because `date_add` is not an [Oracle date function](http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions001.htm#sthref927). The first sentence of this answer is true, but the rest isn't useful for your situation. – Alex Poole May 06 '14 at 15:07