0
的CentOS 6.7 MySQL的73年5月1日MySQL的使用%M高於%M
我有了一個名爲dateTime
列這僅僅是Unix紀元爲每個記錄存檔表返回不同的月份。
我試圖使用下面的查詢來提取月份名稱和月份編號。但%M
正確,但%m
不正確。
正確的結果應該是March
和03
。然而%m
將返回12
mysql> SELECT max(dateTime) FROM archive;
+-----------------+
| max(dateTime) |
+-----------------+
| 1457104500 |
+-----------------+
1 row in set (0.00 sec)
mysql> SELECT max(FROM_UNIXTIME(dateTime,"%M")) as 'date' FROM archive;
+-------+
| date |
+-------+
| March |
+-------+
1 row in set (0.02 sec)
mysql> SELECT max(FROM_UNIXTIME(dateTime,"%m")) as 'date' FROM archive;
+------+
| date |
+------+
| 12 |
+------+
1 row in set (0.02 sec)
爲什麼%m
返回12?
編輯:這是一個有趣的。使用%m %M
產生不同的結果%M %m
mysql> SELECT max(dateTime) FROM archive;
+-----------------+
| max(dateTime) |
+-----------------+
| 1457104500 |
+-----------------+
1 row in set (0.00 sec)
mysql> SELECT max(FROM_UNIXTIME(dateTime,"%M %m")) as 'date' FROM archive;
+----------+
| date |
+----------+
| March 03 |
+----------+
1 row in set (0.02 sec)
mysql> SELECT max(FROM_UNIXTIME(dateTime,"%m %M")) as 'date' FROM archive;
+-------------+
| date |
+-------------+
| 12 December |
+-------------+
1 row in set (0.02 sec)
它總是多數民衆贊成忽略了簡單的解決方案。謝謝! – Pat