Alecs Alecs - 1 year ago 114
SQL Question


Is it a simple way to compare is field of TIMESTAMP type get into last n hours?
I can do the calculation based on the day and time, but is it possible something like

timestamp > SYSDATE - 1

(SYSDATE - 1) is yesterday, as far as understand, so that will check if timestamp is within the last 24 hours.

Thanks in advance.

Answer Source

If you need to look for records within the last n hour, then subtract a time interval from the current time. For Oracle, the quantity of the interval must be in single quotes. There are many intervals you can use (hour, minute, second, day, year, month).

timestampfield > current_timestamp - interval '1' hour
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download