Add 2 hours to current time in MySQL?
MysqlMysql Problem Overview
Which is the valid syntax of this query in MySQL?
SELECT * FROM courses WHERE (now() + 2 hours) > start_time
note: start_time is a field of courses table
Mysql Solutions
Solution 1 - Mysql
SELECT *
FROM courses
WHERE DATE_ADD(NOW(), INTERVAL 2 HOUR) > start_time
See Date and Time Functions for other date/time manipulation.
Solution 2 - Mysql
You need DATE_SUB() OR DATE_ADD()
Solution 3 - Mysql
SELECT * FROM courses WHERE (NOW() + INTERVAL 2 HOUR) > start_time
Solution 4 - Mysql
The http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html#function_date-add">DATE_ADD()</a> function will do the trick. (You can also use the http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html#function_addtime">ADDTIME()</a> function if you're running at least v4.1.1.)
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
Solution 5 - Mysql
This will also work
SELECT NAME
FROM GEO_LOCATION
WHERE MODIFY_ON BETWEEN SYSDATE() - INTERVAL 2 HOUR AND SYSDATE()