Since TIMESTAMP in mysql is stored as a 32-bit value representing the time interval from 1970-jan-1 0:00:00 in seconds, I assumed that using the minus (-) operator in TIMESTAMP values would give a difference of these values in seconds. Not really:
+---------------------------------------------------------------------+
| TIMESTAMP("2010-04-02 10:30:00") - TIMESTAMP("2010-04-02 10:29:59") |
+---------------------------------------------------------------------+
| 41.000000 |
+---------------------------------------------------------------------+
1 row in set (0.05 sec)
mysql> select timestampdiff(SECOND,TIMESTAMP("2010-04-02 10:30:00"),TIMESTAMP("2010-04-02 10:29:59"));
+-----------------------------------------------------------------------------------------+
| timestampdiff(SECOND,TIMESTAMP("2010-04-02 10:30:00"),TIMESTAMP("2010-04-02 10:29:59")) |
+-----------------------------------------------------------------------------------------+
| -1 |
+-----------------------------------------------------------------------------------------+
mysql> select TIMESTAMP("2010-04-02 10:30:00") - TIMESTAMP("2010-04-02 10:30:01") ;
+---------------------------------------------------------------------+
| TIMESTAMP("2010-04-02 10:30:00") - TIMESTAMP("2010-04-02 10:30:01") |
+---------------------------------------------------------------------+
| -1.000000 |
+---------------------------------------------------------------------+
+---------------------------------------------------------------------+
| TIMESTAMP("2010-04-02 10:30:00") - TIMESTAMP("2010-04-02 10:31:00") |
+---------------------------------------------------------------------+
| -100.000000 |
+---------------------------------------------------------------------+
The one minute difference seems to be 100, not 60.
Why is this?
source
share