To add 2 hours to the current time in MySQL, consider utilizing the DATE_ADD function. Its syntax allows you to manipulate date and time values with intervals.
For instance, to retrieve records from the courses table where the start time is greater than the current time plus 2 hours, you can use the following query:
SELECT * FROM courses WHERE DATE_ADD(NOW(), INTERVAL 2 HOUR) > start_time;
The DATE_ADD function accepts two parameters:
Note that the start_time column in the courses table must be of date or datetime data type for this query to be valid.
Remember to explore the DATE and TIME functions for various date and time manipulation scenarios in MySQL.
The above is the detailed content of How Can I Add 2 Hours to the Current Time in MySQL?. For more information, please follow other related articles on the PHP Chinese website!