SQL 调用本机函数“DATEDIFF”时的参数计数不正确
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23250555/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Incorrect parameter count in the call to native function 'DATEDIFF'
提问by Alex Borsody
I get the error from this line
我从这一行得到错误
SELECT table.field
FROM table
WHERE table.month = 'october'
AND DATEDIFF(day, table.start_date, table.end_date) < 30
The dates in my column are in the format m-d-yy
我专栏中的日期格式为 md-yy
Do I need to convert this to a different format? If so how?
我需要将其转换为不同的格式吗?如果是这样怎么办?
Using MariaDB
使用 MariaDB
回答by D Stanley
According to the documentation for MariaDB DATEDIFF
only takes twoarguments:
根据 MariaDB 的文档,DATEDIFF
只需要两个参数:
Syntax
DATEDIFF(expr1,expr2)
Description
DATEDIFF()
returns(expr1 – expr2)
expressed as a value in days from one date to the other.expr1
andexpr2
are date or date-and-time expressions. Only the date parts of the values are used in the calculation.
句法
DATEDIFF(expr1,expr2)
描述
DATEDIFF()
返回(expr1 – expr2)
表示为从一个日期到另一个日期的天数。expr1
andexpr2
是日期或日期和时间表达式。计算中仅使用值的日期部分。
回答by nitinr708
@alex_b it is a very common observation to get confused between the syntaxes of the DATEDIFF & TIMESTAMPDIFF functions. Following linkwill certainly help with the syntax of DATEDIFF & this pagewill list all the others date related functions available in MariaDB's parent MySQL.\
@alex_b 在 DATEDIFF 和 TIMESTAMPDIFF 函数的语法之间混淆是一个非常常见的观察。以下链接肯定会对 DATEDIFF 的语法有所帮助, 此页面将列出 MariaDB 的父 MySQL 中可用的所有其他日期相关函数。\
Referencing the links above below is a summary -
参考上面的链接是一个总结——
TIMEDIFF(expr1,expr2)
expr1 - '2000:01:01 00:00:00'
expr2 - '2000:01:01 00:00:00.000001'
TIMEDIFF() returns expr1 ? expr2 expressed as a time value. expr1 and expr2 are time or date-and-time expressions, but both must be of the same type.
TIMEDIFF() 返回 expr1 ?expr2 表示为时间值。expr1 和 expr2 是时间或日期和时间表达式,但两者的类型必须相同。
DATEDIFF(expr1,expr2)
expr1 - '2007-12-31 23:59:59'
expr2 - '2007-12-30'
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.
DATEDIFF() 返回 expr1 ?expr2 表示为从一个日期到另一个日期的天数。expr1 和 expr2 是日期或日期和时间表达式。计算中仅使用值的日期部分。
Below is the scenario I used it for -
以下是我使用它的场景 -
- using CURDATE for current date as 'argument1'
- using existing varchar column as 'argument2'
- using SET command to update a column
- 使用当前日期的 CURDATE 作为“argument1”
- 使用现有的 varchar 列作为“argument2”
- 使用 SET 命令更新列
SET output_date = DATEDIFF(CURDATE(),input_date), ... above worked for me. Good luck!
SET output_date = DATEDIFF(CURDATE(),input_date), ... 以上对我有用。祝你好运!