在 MySQL 中将当前时间添加 2 小时?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/589652/
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
Add 2 hours to current time in MySQL?
提问by Ei Maung
Which is the valid syntax of this query in MySQL?
MySQL 中此查询的有效语法是什么?
SELECT * FROM courses WHERE (now() + 2 hours) > start_time
note: start_time is a field of courses table
注意:start_time 是课程表的一个字段
回答by Glavi?
SELECT *
FROM courses
WHERE DATE_ADD(NOW(), INTERVAL 2 HOUR) > start_time
See Date and Time Functionsfor other date/time manipulation.
有关其他日期/时间操作,请参阅日期和时间函数。
回答by Sergii
You need DATE_SUB()OR DATE_ADD()
回答by Dani?l van Eeden
SELECT * FROM courses WHERE (NOW() + INTERVAL 2 HOUR) > start_time
回答by lc.
The DATE_ADD()function will do the trick. (You can also use the ADDTIME()function if you're running at least v4.1.1.)
该DATE_ADD()函数就可以了。(如果您至少运行v4.1.1,您也可以使用ADDTIME()函数。)
For your query, this would be:
对于您的查询,这将是:
SELECT *
FROM courses
WHERE DATE_ADD(now(), INTERVAL 2 HOUR) > start_time
Or,
或者,
SELECT *
FROM courses
WHERE ADDTIME(now(), '02:00:00') > start_time
回答by Soumyajit Swain
This will also work -- SELECT NAME from GEO_LOCATION WHERE MODIFY_ON BETWEEN SYSDATE() - INTERVAL 2 HOUR AND SYSDATE()
这也可以工作——SELECT NAME from GEO_LOCATION WHERE MODIFY_ON BETWEEN SYSDATE() - INTERVAL 2 HOUR AND SYSDATE()