Date Shorter and Longer than X days Mysql

Asked

Viewed 2,683 times

0

I have a field on the table called registro_data_instalacao of the kind date, I need to display the logs with the registro_data_instalacao where the date is greater than 3 days and less than 30 days, I tried it in the form below, but without success.

SELECT *
FROM registro
WHERE registro_data_instalacao >= (CURRENT_DATE() + INTERVAL 3 DAY)
  AND registro_data_instalacao <= (CURRENT_DATE() + INTERVAL 30 DAY) 
  • 2

    See if this answers: https://stackoverflow.com/a/2793634/5074998

  • 1

    If the links above and the answer given do not resolve, please [Dit] post with more details.

1 answer

1

You can use the DATE_SUB, as below;

SELECT *
FROM registro
WHERE v.date > (DATE_SUB(CURDATE(), INTERVAL 3 DAY))
  AND v.date < (DATE_SUB(CURDATE(), INTERVAL 30 DAY))

Browser other questions tagged

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