Add 2 hours to current time in MySQL?

Viewed 278914

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

5 Answers
SELECT * 
FROM courses 
WHERE DATE_ADD(NOW(), INTERVAL 2 HOUR) > start_time

See Date and Time Functions for other date/time manipulation.

The DATE_ADD() function will do the trick. (You can also use the ADDTIME() 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
Related