
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to subtract 3 hours from a datetime in MySQL?
Subtract 3 hours from DateTime in MySQL, using any of the following ways. The first approach is as follows −
Case 1 − Using DATE_ADD()
select date_add(yourColumnName,interval -3 hours) from yourTableName;
Case 2 − Using DATE_SUB()
select date_sub(yourColumnName,interval 3 hours) from yourTableName;
Firstly, use now() to get the current date-time −
mysql> select now();
The following is the output −
+---------------------+ | now() | +---------------------+ | 2018-11-30 10:13:23 | +---------------------+ 1 row in set (0.00 sec)
DATE_ADD
The query to subtract 3 hours from DateTime is as follows. With date_add, we have set a negative date −
mysql> select date_add(now(),interval -3 hour);
The following is the output −
+----------------------------------+ | date_add(now(),interval -3 hour) | +----------------------------------+ | 2018-11-30 07:13:28 | +----------------------------------+ 1 row in set (0.00 sec)
DATE_SUB
Get the current date and time −
mysql> select now();
The output −
+---------------------+ | now() | +---------------------+ | 2018-11-30 10:14:12 | +---------------------+ 1 row in set (0.00 sec)
Implement the second method using date_sub(). The query is as follows −
mysql> select date_sub(now(),interval 3 hour);
The following output displays the date subtracting 3 hours −
+---------------------------------+ | date_sub(now(),interval 3 hour) | +---------------------------------+ | 2018-11-30 07:14:25 | +---------------------------------+ 1 row in set (0.00 sec)
- Related Articles
- How to subtract 30 days from the current datetime in MySQL?
- How to subtract 10 days from the current datetime in MySQL?
- How to Add or Subtract Hours from a Date/Time Field in Excel?
- MySQL DateTime Now()+5 days/hours/minutes/seconds?
- Subtract (+3) from (-3)
- Java Program to subtract hours from current time using Calendar.add() method
- How to part DATE and TIME from DATETIME in MySQL?
- Subtract 4 hours 20 minutes 36 seconds from 8 hours 18 minutes 20 seconds.
- How to convert JavaScript datetime to MySQL datetime?
- How to select only MySQL date from datetime column?
- How to subtract seconds from all the date records in a MySQL column?
- How to convert DateTime to a number in MySQL?
- MySQL how to declare a datetime variable?
- Remove seconds from MySQL Datetime?
- How to Add or Subtract Times to Get Hours/Minutes/ Seconds in Excel?

Advertisements