如何在 MySQL 中使用 DATEADD?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25548423/
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
How to use DATEADD in MySQL?
提问by Bart Scheffer
I have a problem and I can't figure out the solution. With a previously asked question (SELECT rows with time 30 minutes or less?) I tried to make my COUNT(*) function work but I can't make it work. Anybody an idea?
我有一个问题,我想不出解决办法。对于先前提出的问题(SELECT 行的时间为 30 分钟或更短?)我试图让我的 COUNT(*) 函数工作,但我无法让它工作。有人有想法吗?
SELECT COUNT(*) FROM g_ad_view WHERE ad_view_time >= DATEADD(mi, -30, GETDATE())
And this is the error I get back:
这是我回来的错误:
SQLSTATE[42000]: Syntax error or access violation: 1305 FUNCTION 18RVS15.DATEADD does not exist
SQLSTATE[42000]:语法错误或访问冲突:1305 FUNCTION 18RVS15.DATEADD 不存在
回答by Gordon Linoff
The MySQL syntax is:
MySQL 语法是:
WHERE ad_view_time >= now() - interval 30 minute
回答by Jens
DateAdd is missspelled: It must be DATE_ADD (with underscore). See the documentation
DateAdd 拼写错误:它必须是 DATE_ADD(带下划线)。查看文档
回答by Gebru Welay
you can use DATE_SUB(CURDATE(), INTERVAL 30 minute)
您可以使用 DATE_SUB(CURDATE(), INTERVAL 30 分钟)