Home  >  Article  >  Database  >  mysql的一个日期有关问题,理解不了

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

WBOY
WBOYOriginal
2016-06-07 16:24:37995browse

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)

注意红色部分,谁给解释一下?
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn