要将时间戳转换为月份,请使用FROM_UNIXTIME()方法,如以下语法所示:select month(from_unixtime(yourColumnName)) from yourTableName;
让我们首先创建一个表-mysql> create table DemoTable1457
-> (
-> Value bigint
-> );
使用插入命令在表中插入一些记录-mysql> insert into DemoTable1457 values(1570207117);
mysql> insert into DemoTable1457 values(1548947534);
mysql> insert into DemoTable1457 values(1575213134);
使用select语句显示表中的所有记录-mysql> select * from DemoTable1457;
这将产生以下输出-+------------+
| Value |
+------------+
| 1570207117 |
| 1548947534 |
| 1575213134 |
+------------+
3 rows in set (0.00 sec)
以下是将时间戳转换为月份的查询-mysql> select month(from_unixtime(Value)) from DemoTable1457;
这将产生以下输出-+-----------------------------+
| month(from_unixtime(Value)) |
+-----------------------------+
| 10 |
| 1 |
| 12 |
+-----------------------------+
3 rows in set (0.00 sec)