2
How do I show the date and time after the user sends a message?
I created in the database a column called 'date' of type 'DATETIME'.
In php I used the following code to insert the data:
Inserir.php
$sql = "INSERT INTO autoriza (ID, data) VALUES( '$id', 'NOW()')";
$acao_sql = $mysqli->query($sql);
Lista.php
$sql = "SELECT * FROM autoriza ORDER BY ID DESC";
$acao_sql = $mysqli->query($sql);
while ($lista = $acao_sql->fetch_array(MYSQLI_ASSOC)){
echo "Recado enviado em: ".$lista['data'];
}
The above result shows: 0000-00-00 00:00:00
I managed using the following code: date_default_timezone_set('America/Sao_paulo'); $mysqldata = new Datetime(); $data = $mysqldata->format(Datetime::ISO8601);$sql = "INSERT INTO authorizes (ID, date, name, Cpf) VALUES( '$id', '$data', '$name', '$Cpf')"; $acao_sql = $qli->query($sql);
– GustavoCave