To add 2 hours in the current time, we will use the DATE_ADD() function. mysql> select DATE_ADD(now(),interval 2 hour);
MySQL ADDTIME() function In MySQL the ADDTIME() returns a time or datetime after adding a time value with a time or datetime.
MySQL NOW() Function The NOW() function returns the current date and time. Note: The date and time is returned as "YYYY-MM-DD HH-MM-SS" (string) or as YYYYMMDDHHMMSS. uuuuuu (numeric).
The DATE_SUB() function subtracts a time/date interval from a date and then returns the date.
SELECT *
FROM courses
WHERE DATE_ADD(NOW(), INTERVAL 2 HOUR) > start_time
See Date and Time Functions for other date/time manipulation.
You need DATE_SUB() OR DATE_ADD()
SELECT * FROM courses WHERE (NOW() + INTERVAL 2 HOUR) > start_time
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
This will also work
SELECT NAME
FROM GEO_LOCATION
WHERE MODIFY_ON BETWEEN SYSDATE() - INTERVAL 2 HOUR AND SYSDATE()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With