MySQL中提供了很多函数,为我们的SQL操作提供便利,例如:
mysql> select NOW(), DATE_FORMAT( NOW(),'%Y-%m-%d %H:%i:%s') as time;
+---------------------+---------------------+
| NOW() | time |
+---------------------+---------------------+
| 2021-10-14 14:28:09 | 2021-10-14 14:28:09 |
+---------------------+---------------------+
mysql> select NOW(), DATE_FORMAT( NOW(),'%Y-%m-%d') as time;
+---------------------+------------+
| NOW() | time |
+---------------------+------------+
| 2021-10-14 14:28:58 | 2021-10-14 |
+---------------------+------------+