Query sql with longer and shorter date limit

Asked

Viewed 3,159 times

0

My code should return values from the database, related to the current day (today), but only related to the month and day, I searched a lot but could not find something to help me

$data_atual = date("d-m");
$mostraDados = mysqli_query($conecta,  "SELECT * FROM sql WHERE ativo = 's' AND inicio >= '".$data_atual."'")or die (mysqli_error());

in the column inicio of the table is the date, for example 13-10, then the query line should return everything above the 13th day of the 10th month, but this giving error. In this case, the variable $data_atual takes the server’s day and month to query and check with the start column.

  • Which error is returning ?

  • 1

    https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html use data functions as year(0 , Month() and now()

  • the error is that it does not return the values @Wéllingthonm.

  • @Motta , had forgotten the NOW() function, I’m now searching to see if I can solve the code

1 answer

2

You’ll have to use function DATE() to convert the two dates to the "yyyy-mm-dd" format and compare them. So to get all today’s date records, you would have the following query:

SELECT * FROM sql WHERE ativo = 's' AND DATE(inicio) >= DATE(NOW())

Browser other questions tagged

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