Home > database >  selecting all records 14 days from the current date
selecting all records 14 days from the current date

Time:12-08

I am trying to get all records that have a date not further than 14 days from the current date.

Today's date is 12/7/2021.

When I run the following:

select sysdate   14 from dual

I get the following results:

12/21/2021 9:16:25 PM

Therefore, I should not be getting any records past the above date.

The column I am looking at is eta. Here is the query:

select
  full_name
  eta
from table
where eta > sysdate   14

But when I run that query, I am getting dates as far out as in April and May.

How do I correct this?

CodePudding user response:

All you are doing with where eta > sysdate 14 is asking for records with an eta greater than 14 days from current database date. What you want is a between:

select
  full_name
  eta
from table
where eta between sysdate and sysdate   14

This will give you any record with an eta between today and 14 days from now.

If you want records up to 14 days into the future, regardless of a lower bound, then you want:

select
  full_name
  eta
from table
where eta <= sysdate   14

CodePudding user response:

Should've been

where eta <= sysdate   14

as you said that you

should not be getting any records past the above date.

  • Related