What would the query look like to return values in a given range?

Asked

Viewed 328 times

3

I have a table with the following Rows:

  • code (int)
  • vaccine (varnish)
  • dt_maturity (datetime)

I need a query to return all vaccines that will win in the interval of 10 days, counting today’s date.

I tried something like this I saw in that replySoen using INTERVAL:

SELECT * FROM tblVacinas WHERE dt_vencimento >= DATE_ADD(CURDATE(), INTERVAL 10 DAY);

Obs.: didn’t work.

How would the query to return values in a given range from the current date?

  • 2

    Fetch last 7 days data from current date Detail you need to compare the correct units, use date_format() dt_maturity to specify the correct format (delete time, minute and seconds) to search. date = year, month and day; datetime = year, month, day, hour, minute and second.

  • I think you meant Chris and not Chris.

2 answers

1

The problem with your query is that in this part >= DATE_ADD(CURDATE(), INTERVAL 10 DAY) you say to search for dates that are greater or equal today’s date plus 10 days, example: on 23/01/2017 your query will only fetch dates beyond 02/02/2017.

If you want to seek a break, just use the BETWEEN:

SELECT * 
FROM tblVacinas
WHERE dt_vencimento BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 10 DAY);

0

Browser other questions tagged

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