How to echo a select DATEDIFF?

Asked

Viewed 29 times

1

I made the next 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 nothing returns. what’s wrong?

1 answer

1


The variable $data should be in quotes:

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

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

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

Browser other questions tagged

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