要获取日期名称,请使用DAYNAME()
MySQL中的function。让我们首先创建一个表-
mysql> create table DemoTable1954 ( ShippingDate date );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1954 values('2019-12-15'); mysql> insert into DemoTable1954 values('2018-04-11'); mysql> insert into DemoTable1954 values('2019-01-31'); mysql> insert into DemoTable1954 values('2016-10-01');
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1954;
这将产生以下输出-
+--------------+ | ShippingDate | +--------------+ | 2019-12-15 | | 2018-04-11 | | 2019-01-31 | | 2016-10-01 | +--------------+ 4 rows in set (0.00 sec)
这是获取对应日期的日期名称的查询:
mysql> select dayname(ShippingDate) as Day from DemoTable1954;
这将产生以下输出-
+-----------+ | Day | +-----------+ | Sunday | | Wednesday | | Thursday | | Saturday | +-----------+ 4 rows in set (0.00 sec)