Now () MySQL does not display the correct time

3

I need some way to insert the EXATA time from the server who sends a message to the database.

I'musingtheNOW()functiontoregisterthemoment:

"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 does not record the time correctly.

  

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

    
asked by anonymous 14.07.2015 / 13:51

1 answer

5

This is a Time Zone issue:

The time_zone variable can be set directly on the MySQL client console.

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

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

SELECT NOW();

If you have the zone database of zone names properly configured, you can refer to zones by their names:

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