要在MySQL中获取日期的最后一秒,请使用INTERVAL命令。让我们首先创建一个表-
mysql> create table DemoTable -> ( -> JoiningDatetime datetime, -> DueDatetime datetime -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable(JoiningDatetime) values('2019-11-03 12:34:54'); mysql> insert into DemoTable(JoiningDatetime) values('2019-10-04 12:34:54');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+---------------------+-------------+ | JoiningDatetime | DueDatetime | +---------------------+-------------+ | 2019-11-03 12:34:54 | NULL | | 2019-10-04 12:34:54 | NULL | +---------------------+-------------+ 2 rows in set (0.00 sec)
这是获取MySQL中日期的最后一秒的查询-
mysql> update DemoTable -> set DueDatetime=DATE(JoiningDatetime) + INTERVAL 1 DAY - INTERVAL 1 SECOND; Rows matched: 2 Changed: 2 Warnings: 0
让我们再次检查表记录-
mysql> select *from DemoTable;
这将产生以下输出-
+---------------------+---------------------+ | JoiningDatetime | DueDatetime | +---------------------+---------------------+ | 2019-11-03 12:34:54 | 2019-11-03 23:59:59 | | 2019-10-04 12:34:54 | 2019-10-04 23:59:59 | +---------------------+---------------------+ 2 rows in set (0.00 sec)