calculating date in mysql update

1

Well I need to update my accounts that are over 5 months old, I wanted to do this right in mysql. The update looks like this:

UPDATE contas
SET baixa_valivade = true
WHERE data_vencimento (Preciso verificar se já esta vencida a mais de 5 meses)
    
asked by anonymous 26.09.2018 / 18:16

1 answer

3

Use DATE_ADD () :

UPDATE contas
SET baixa_valivade = true
WHERE data_vencimento BETWEEN DATE_ADD(CURRENT_DATE(), INTERVAL -5 MONTH) AND CURRENT_DATE()

If the need is to update items with a delay date greater than 5 months, the code would look like this:

UPDATE contas
SET baixa_valivade = true
WHERE data_vencimento < DATE_ADD(CURRENT_DATE(), INTERVAL -5 MONTH)
    
26.09.2018 / 18:24