Skip to content
Advertisement

oracle sql – get difference between 2 dates (sysdate minus the datevalue of a other table)

I want to know the difference betweeen 2 dates.

I need something like this: “sysdate minus the datevalue of a other table”

Currently I have something like this, but it’s not working

SELECT something FROM myTable1 WHERE mydate >= sysdate-(SELECT latestExport FROM myTable2 WHERE id=1);

The 2nd select statement prints the date of the latest export. Example “27-JUL-21”.

thanks for your help.

Advertisement

Answer

It can not work. Because the result of

sysdate-(SELECT latestExport FROM myTable2 WHERE id=1)

is a decimal value. For example 5121.2 days difference between SYSDATE and latestExport and you can not compare your Date value mydate with a decimal. This is the logic you used:

Is "25-10-2020" >= 5121.2 ?

You need to think again about the result you want to get from this query.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement