Mysql now() does not display the correct time

Asked

Viewed 471 times

3

I need to somehow insert into the server the time EXACT who sends a message to the database.

ENVIADA AS 08:15 E 08:17

I’m using the function NOW() to record the moment:

"INSERT INTO `chat` (id_de, id_para, data, mensagem, hora) VALUES('$id_de','$id_para',NOW(),'$mensagem', DATE_FORMAT(now(), '%H:%i:%s'))"

However, it still doesn’t record the time correctly..

Testing the 08:17 // 14-07-2015 - PC -->> 11:17:25

  • How are you generating the date in the $message variable? Using some PHP function?

1 answer

5


This is a Time Zone problem:

The time_zone variable can be adjusted directly in the Mysql client console.

SET @@global.time_zone = '+3:00';
QUIT

You need to log out and log back into your Mysql session in order to see the effects. Once you restart your Mysql session, check the current time again:

SELECT NOW();

If you have the appropriate time zone name database configured, you can refer to the zones by their names:

SET time_zone='America/Sao_Paulo';
Query OK, 0 rows affected (0.01 sec)

Browser other questions tagged

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