要从时间戳获取日期名称,请使用dayname()
方法-
select dayname(yourColumnName) from yourTableName; Let us first create a table : mysql> create table DemoTable ( LoginDate timestamp );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('2019-06-01'); mysql> insert into DemoTable values('2019-06-02'); mysql> insert into DemoTable values('2019-06-03'); mysql> insert into DemoTable values('2019-06-04'); mysql> insert into DemoTable values('2018-06-21');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
+-----------------------+ | LoginDate | +-----------------------+ | 2019-06-01 00 :00 :00 | | 2019-06-02 00 :00 :00 | | 2019-06-03 00 :00 :00 | | 2019-06-04 00 :00 :00 | | 2018-06-21 00 :00 :00 | +-----------------------+ 5 rows in set (0.00 sec)
以下是从MySQL中的时间戳获取日期名称的查询-
mysql> select dayname(LoginDate) from DemoTable;
输出结果
+--------------------+ | dayname(LoginDate) | +--------------------+ | Saturday | | Sunday | | Monday | | Tuesday | | Thursday | +--------------------+ 5 rows in set (0.00 sec)