I am writing an SQL query which involves finding if timestamp falls in particular range of days.
I have written that in the PostgreSQL but it doesn’t works in Oracle and SQL Server:
AND creation_date < (CURRENT_TIMESTAMP - interval '5 days')
AND creation_date >= (CURRENT_TIMESTAMP - interval '15 days')
Is there are common way to compare the timestamp across different databases?
I’m not a SQL Server expert but I know this works on Oracle and Postgres and I suspect it may work on MSSQL but have no way to test it ATM.
Or if you are using the date type instead of timestamp, you could do this but I’m pretty sure it wouldn’t work on MSSQL. And the DATE type is quite different between Oracle and Pg.
As was noted in the comments for OMG Ponies, you can only add ints to Date types not timestamps. (Oracle silently casts the timestamp to date)