I keep getting an error trying to implement DATE_DIFF in mySQL.
在mySQL中,我一直在尝试实现DATE_DIFF。
I'm trying to get the number of days between "hm_date" and the present day, and have the number appear in a different field called "total_days".
我试图在“hm_date”和现在之间获得天数,并将这个数字显示在一个名为“total_days”的不同字段中。
Doing this on servier-side, my code is getting an error: #1305 - FUNCTION naturan8_41q.DATE_DIFF does not exist
在服务器端执行这个操作,我的代码会得到一个错误:#1305 - FUNCTION naturan8_41q。DATE_DIFF不存在
SELECT * FROM reg_add WHERE DATE_DIFF(hm_date,total_days)
3 个解决方案
#1
1
You are using DATE_DIFF
, thats the error. DATEDIFF is the correct function name.
您使用的是DATE_DIFF,这是错误。DATEDIFF是正确的函数名。
Corrected Query: SELECT DATEDIFF(curdate(),hm_date) as total_days FROM reg_add.
更正后的查询:从reg_add中选择DATEDIFF(curdate(),hm_date)作为total_days。
#2
2
DATEDIFF
is the correct name, without spaces (indeed, it is confusing and inconsistent with DATE_ADD
and DATE_FORMAT
)
DATEDIFF是正确的名称,没有空格(实际上,它是混乱的,与DATE_ADD和DATE_FORMAT不一致)
#3
1
SELECT DATEDIFF(curdate(), hm_date) as total_days FROM reg_add
#1
1
You are using DATE_DIFF
, thats the error. DATEDIFF is the correct function name.
您使用的是DATE_DIFF,这是错误。DATEDIFF是正确的函数名。
Corrected Query: SELECT DATEDIFF(curdate(),hm_date) as total_days FROM reg_add.
更正后的查询:从reg_add中选择DATEDIFF(curdate(),hm_date)作为total_days。
#2
2
DATEDIFF
is the correct name, without spaces (indeed, it is confusing and inconsistent with DATE_ADD
and DATE_FORMAT
)
DATEDIFF是正确的名称,没有空格(实际上,它是混乱的,与DATE_ADD和DATE_FORMAT不一致)
#3
1
SELECT DATEDIFF(curdate(), hm_date) as total_days FROM reg_add