We will base the logic around sysdate
which returns the current datetime, from which we substract different units. For example for the last day from now use sysdate - 1
(units default 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/24)
-- last 2 hours
select count(*)
from PARTNER
WHERE CREATED_AT > (sysdate - 2/24)
Shared with ❤️ from Codever. 👉 use the copy to mine functionality to add it to your personal snippets collection.
Top comments (2)
"last hour" example is wrong. Should be 1/24.
Also: nice post
Thanks Erik, missed that :)