Right now I have a SQL query that allows me to select entries in a table that have been inserted over the past day.
The query is:
Select account from mytable where create_date > current_timestamp - 1
But suppose that I wanted to select entries that had been inserted over the base two hours?
How would I write that query?
You can use DATEADD, like so:
SELECT account
FROM MyTable
WHERE create_date > DATEADD(hh, -2, GETDATE())
Consider that a timestamp and a datetime are extremely different in sql server. A timestamp is a unique binary number whereas a datetime is a date and time combination. I think you'll need datetime.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With