PHP strtotime returns another Mysql UNIX_TIMESTAMP value

I was looking for a message on stackoverflow, found some similar messages. But I think this is different.

My PHP and Mysql server time zone is set to "UTC".

In the table, I use the timestamp field, the value is "2010-11-08 02:54:15", I use sql as follows:

SELECT id, updated, second( updated ) , unix_timestamp( updated ) FROM `transaction` where id = 56 

Gets the following:

 id updated second unix -------------------------------------------- 56 2010-11-08 02:54:15 15 1289184879 

Then I use this in php:

 echo strtotime("2010-11-08 02:54:15"); 

Gets the following:

 1289184855 

The difference is 24 seconds.

And I will check these timestamps at http://www.unixtimestamp.com/index.php The php result is correct. So does mysql unix_timestamp function have an error? Mysql Version: 5.1.41

+4
source share
2 answers

This is confirmed as a bug, which is fixed in 5.1.44.

See http://bugs.mysql.com/bug.php?id=51918 for more details, and this error was discovered in this post.

You will have no choice but to upgrade to avoid his looks.

+4
source

I cannot reproduce this in MySQL 5.1.41 on Linux. Perhaps this is only Windows?

 snip@ssnip :~$ mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 295 Server version: 5.1.41 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> select unix_timestamp("2010-11-08 02:54:15"); +---------------------------------------+ | unix_timestamp("2010-11-08 02:54:15") | +---------------------------------------+ | 1289206455 | +---------------------------------------+ 1 row in set (0.00 sec) mysql> exit Bye maia@sloodle :~$ php -a Interactive shell php > echo strtotime("2010-11-08 02:54:15"); 1289206455 php > exit snip@ssnip :~$ mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 297 Server version: 5.1.41 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> select from_unixtime(1289206455); +---------------------------+ | from_unixtime(1289206455) | +---------------------------+ | 2010-11-08 02:54:15 | +---------------------------+ 1 row in set (0.00 sec) 
0
source

All Articles