CURDATE() with day and time

Asked

Viewed 149 times

4

In Mysql I have a table with field type DATETIME, with this value: 2019-08-01 15:30:00

For control, today is day 01/08/2019 15:05:00

I want to do a query that only shows if the date in the database is less than the current date, so I did this:

WHERE DATE(noticia.dia) <= CURDATE()

But he is ignoring the time, taking only into account the day and showing in the result the date 2019-08-01 15:30:00, where error?

1 answer

5


The function CURDATE returns only the date, no time, so your condition is considering 00:00:00, past. You can use NOW(). The function DATE that you used is also removing the time from the other side, so the solution would be:

WHERE noticia.dia <= NOW()

Browser other questions tagged

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