Compare Date within Mysql

1

I'm trying to select the date closest to the current date, but I'm not getting a good result.

The insertion is:

$titulo = trim($_POST["titulo"]);
$descricao = trim($_POST["descricao"]);
$data = $_POST['data'];

the query is:

SELECT * FROM eventos WHERE data > GETDATE() LIMIT 1

What I need is to get the DATA column in the event table where the registered DATA is greater than the current date.

    
asked by anonymous 20.07.2015 / 15:11

1 answer

4

You can develop as follows:

$DataAtual = date("Y-m-d"); 
$sql = "SELECT * FROM tabela WHERE data > {$DataAtual}";

This looks for records that are larger than the current date.

Or if the $ date comes from the Post, do:

$DataAtual = $_POST['data'];
$DataAtual = date("Y-m-d", strtotime($_POST['data'])); // caso a data venha em formato 00/00/0000 
$sql = "SELECT * FROM tabela WHERE data > {$DataAtual}";
  

Remember that the command data > {$DataAtual} only serves if the date is GREATER than the posted date, if it is equal or greater, you must use data >= {$DataAtual} .

This documentation can help you: link

    
20.07.2015 / 15:15