Home > Database > Mysql Tutorial > How Can I Add 2 Hours to the Current Time in MySQL?

How Can I Add 2 Hours to the Current Time in MySQL?

Barbara Streisand
Release: 2024-12-03 15:29:14
Original
205 people have browsed it

How Can I Add 2 Hours to the Current Time in MySQL?

Adjusting Time with MySQL: Adding 2 Hours to the Current Time

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;
Copy after login

The DATE_ADD function accepts two parameters:

  • NOW(): Represents the current date and time.
  • INTERVAL 2 HOUR: Specifies the interval to add to the current time, which in this case is 2 hours.

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template