让我们首先创建一个表-
mysql> create table DemoTable -> ( -> DueDate date -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('2019-01-11'); mysql> insert into DemoTable values('2019-04-19');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+------------+ | DueDate | +------------+ | 2019-01-11 | | 2019-04-19 | +------------+ 2 rows in set (0.00 sec)
以下是显示月份的第一天和最后一天的查询-
mysql> select date_format(DueDate,'%Y-%m-01') as FirstDayOfMonth,last_day(DueDate) as LastDayOfMonth from DemoTable;
这将产生以下输出-
+-----------------+----------------+ | FirstDayOfMonth | LastDayOfMonth | +-----------------+----------------+ | 2019-01-01 | 2019-01-31 | | 2019-04-01 | 2019-04-30 | +-----------------+----------------+ 2 rows in set (0.00 sec)