How to get the current date in Mysql?

Asked

Viewed 33,357 times

5

I intend to create an event so that every hour will see if the expiration date of the announcement is higher than the current date, in this case it will have to change a theme of this announcement in the database, that is, it would be something like this that I tried, but I doubt how to get the instantaneous date:

    CREATE EVENT e
    ON SCHEDULE EVERY 1 HOUR
    DO UPDATE anuncios SET estado=3 WHERE dataexpiracao > -data actual-

2 answers

9

Just use NOW():

CREATE EVENT e
ON SCHEDULE EVERY 1 HOUR
DO UPDATE anuncios SET estado=3 WHERE dataexpiracao > NOW()
  • Okay I really appreciate

6

Just use the function NOW()

Ex:

SELECT NOW()

Return:

2015-04-29 12:07:45

Follows documentation: NOW

  • OK thanks for the help

Browser other questions tagged

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