我需要获取 MySQL 上几个日期中包含的天数。
例如:
12-04-2010
15-04-2010
天差为 3。
最佳答案
呢? DATEDIFF 功能 ?
引用手册页:
DATEDIFF() returns expr1 – expr2 expressed as a value in days from one date to the other. expr1 and expr2 are date or date-and-time expressions. Only the date parts of the values are used in the calculation
在你的情况下,你会使用:
mysql> select datediff('2010-04-15', '2010-04-12');
+--------------------------------------+
| datediff('2010-04-15', '2010-04-12') |
+--------------------------------------+
| 3 |
+--------------------------------------+
1 row in set (0,00 sec)
但请注意,日期应写为
YYYY-MM-DD
,而不是 DD-MM-YYYY
就像你发布的那样。
关于mysql - 如何获取 MySQL 上两个日期之间相差的天数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53701265/