How to do an echo of a select DATEDIFF?

0

I made the following code

$data_restante = "SELECT DATEDIFF(CURTIME(),$data) AS date";
$result_data_res = mysqli_query($conn, $data_restante);
$dado_data_res = mysqli_fetch_assoc($result_data_res);
echo $dado_data_res['date'];

But it does not return anything. What is wrong?

    
asked by anonymous 15.02.2018 / 00:22

1 answer

1

The variable $data should be enclosed in quotation marks:

"SELECT DATEDIFF(CURTIME(),'$data') AS date"

But also the variable can not be a literal string. Before you should convert it to date format:

$data = "2018-02-01";
$data = date('Y-m-d',strtotime($data));
    
15.02.2018 / 01:12