Decrease a Mysql value

Asked

Viewed 287 times

-2

Is there any Mysql attribute to Decrement Day , month , year or time in the database itself that would be automatically.

Ex: column-> starting value = 15, after a day would be 14

The mysql database does this ???

  • Better [Dit] post and explain what you want at least with a clear example. The way you look, you can’t be too sure what you’re looking for. Even because it doesn’t make much sense for a date operation to be contrary to an auto increment, and the nature of the data is quite different. It seems to me that your question refers to a XY problem

  • Ai face to understand now

  • @Bacco would be an example a paid system after a month of testing is blocked the user account until it pays.

  • 1

    It really is an XY problem, your question stuck in the way you thought it would solve, and not in your real doubt, which is "how to block a system after a month of testing" (whose answer probably doesn’t even go through what is in your question, would be enough a IF data > prazo de teste). The solution really would be to completely remake the question with your real doubt.

2 answers

0


Automatically it does not have, but there are some approaches to do this.

The simplest is to implement in the query itself that makes the update, follow an example:

UPDATE tabela SET
    campo1 = 'Teste',
    campoData = DATE_ADD(campoData, INTERVAL -1 DAY)
WHERE
    (id = 1);

0

You can create a Rigger or event (Trigger only occurs when an operation is triggered, type Insert, delete, update) to perform this operation daily, for example:

CREATE EVENT event1
ON SCHEDULE EVERY '1' DAY
DO
-- sua operação aqui, por exemplo:
   UPDATE TABELA SET CAMPODATA = str_to_date( date_format(now(), '%Y%m%d 0200'), '%Y%m%d %H%i' ) - INTERVAL 1 DAY
END

Browser other questions tagged

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