Count entries created recently in an oracle database

We will base the logic around sysdate which returns the current datetime, from which we substract units. For example for the last day from now use sysdate - 1 (defaults to day) and compare with the timestamp column (in this case CREATED_AT) :

select count(*)
from PARTNER
WHERE CREATED_AT > (sysdate - 1)

-- last 2 days would be
select count(*)
from PARTNER
WHERE CREATED_AT > (sysdate - 2)

From the last hour, respectively last two hours use the following commands, where 1/24 is the unit for hour:

-- last hour
select count(*)
from PARTNER
WHERE CREATED_AT > (sysdate - 1)

-- last 2 hours
select count(*)
from PARTNER
WHERE CREATED_AT > (sysdate - 2/24)

Shared with from Codever.land. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Subscribe to our newsletter for more code resources and news

Adrian Matei

Adrian Matei
Life force expressing itself as a coding capable human being

How to get current time in java enterprise and be easily testable

How to get current time in java enterprise and be easily testable code snippet Continue reading