首页 > 文章列表 > 如何在 MySQL 查询中向 DATETIME 字段添加一天?

如何在 MySQL 查询中向 DATETIME 字段添加一天?

451 2023-08-26

借助 DATE_ADD() 函数,我们可以向表的 DATETIME 字段添加一天。

mysql> Select StudentName, RegDate, Date_ADD(RegDate, INTERVAL +1 day) AS 'NEXT DAY'
       from testing where StudentName = 'gaurav';

+-------------+---------------------+---------------------+
| StudentName | RegDate             | NEXT DAY            |
+-------------+---------------------+---------------------+
| Gaurav      | 2017-10-29 08:48:33 | 2017-10-30 08:48:33 |
+-------------+---------------------+---------------------+
1 row in set (0.00 sec)

以上查询将在名为“testing”的 MySQL 表中的 RegDate(其中 StudentName 为 Gaurav)中添加一天。