如何在 MySQL 中从时间戳获取日期名称?
要从时间戳中获取日期名称,请使用 dayname() 函数 −
select dayname(yourColumnName) from yourTableName; Let us first create a table : mysql> create table DemoTable ( LoginDate timestamp ); Query OK, 0 rows affected (0.52 sec)
使用插入命令在表中插入一些记录 −
mysql> insert into DemoTable values('2019-06-01'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('2019-06-02'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('2019-06-03'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('2019-06-04'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('2018-06-21'); Query OK, 1 row affected (0.09 sec)
使用 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)
广告