How to compare two Oracle Datetime columns

Asked

Viewed 340 times

0

I have a column where I enter a date when the event happens (local storage), and the date when the event is sent to my system.

The difference between the date of the event and the date of dispatch must not exceed 168 hours (7 days).

I would like to select all the data that event data + 168h is less than the shipping data.

SELECT * FROM VENDA
WHERE (DATA_VENDA+ 168HOURAS) < DATA_ENVIO_VENDA;

I’m using Oracle database.

1 answer

1


You can add 7 days which is the equivalent of 168h:

Sqlfiddle - Online Example:

SELECT * FROM VENDA WHERE (DATA_VENDA + 7) < DATA_ENVIO_VENDA
  • Will this take into account the time as well or just the date? example: sale day 01/xx/xxxx at 12:00:00 and shipping day 08/xx/xxxx at 11:59:00, this will give me a false positive? Anyway I will test.

  • 1

    Will take into account the time yes, in the example you gave the condition of the where will not be satisfied and therefore will not return this line. I updated the example that is on the answer link to simulate your question.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.