Select that picks up the last 30 days from the current date

2

Good morning, this is a part of query that I used to fetch the last days from the current date. It works as expected when I put -20 , but putting -30 does not.

WHERE viacao_os.creation_date BETWEEN CURRENT_DATE() -30 AND CURRENT_DATE()

How can I see what was created in the last 30 days?

    
asked by anonymous 21.03.2018 / 15:35

1 answer

3

Use DATE_ADD() :

WHERE viacao_os.creation_date
    BETWEEN DATE_ADD(CURRENT_DATE(), INTERVAL -30 DAY) AND CURRENT_DATE()

Possibly your query works with -20 because we are on day 21 , that is, perhaps.

    
21.03.2018 / 15:38