欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

mysql的一个日期有关问题,理解不了

程序员文章站 2022-05-26 09:46:42
...

mysql的一个日期问题,理解不了 mysql select date_sub( '2014-03-04' ,interval dayofmonth(curdate())-1 day); +-------------------------------------------------------------+ | date_sub('2014-03-04',interval dayofmonth(curdate())-1 day) | +-----

mysql的一个日期问题,理解不了
mysql> select date_sub('2014-03-04',interval dayofmonth(curdate())-1 day);
+-------------------------------------------------------------+
| date_sub('2014-03-04',interval dayofmonth(curdate())-1 day) |
+-------------------------------------------------------------+
| 2014-02-14 |
+-------------------------------------------------------------+
1 row in set (0.00 sec)

把这个日期插入到表中:
mysql> select * from t_date_3;
+---------------------+------+
| t_create | val |
+---------------------+------+
| 2014-03-17 14:08:13 | 6 |
| 2014-03-17 14:08:31 | 11 |
| 2014-03-04 00:00:00 | NULL |
+---------------------+------+
3 rows in set (0.00 sec)

然后:
mysql> select date_sub(t_create,interval dayofmonth(t_create)-1 day) from t_date
_3;
+--------------------------------------------------------+
| date_sub(t_create,interval dayofmonth(t_create)-1 day) |
+--------------------------------------------------------+
| 2014-03-01 14:08:13 |
| 2014-03-01 14:08:31 |
| 2014-03-01 00:00:00 |
+--------------------------------------------------------+
3 rows in set (0.00 sec)

注意红色部分,谁给解释一下?