
- 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
Increment date/time value by second with MySQL query?
For this, use date_add() with interval command. Let us first create a table −
mysql> create table DemoTable1867 ( ArrivalTime datetime ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1867 values('2019-10-12 12:34:45'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1867 values('2019-10-12 10:04:15'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1867 values('2019-10-12 11:00:23'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1867;
This will produce the following output −
+---------------------+ | ArrivalTime | +---------------------+ | 2019-10-12 12:34:45 | | 2019-10-12 10:04:15 | | 2019-10-12 11:00:23 | +---------------------+ 3 rows in set (0.00 sec)
Here is the query to increment date/time value by second with MySQL query −
mysql> select date_add(ArrivalTime, interval 5 second) from DemoTable1867;
This will produce the following output −
+------------------------------------------+ | date_add(ArrivalTime, interval 5 second) | +------------------------------------------+ | 2019-10-12 12:34:50 | | 2019-10-12 10:04:20 | | 2019-10-12 11:00:28 | +------------------------------------------+ 3 rows in set (0.00 sec)
- Related Articles
- Update MySQL date and increment by one Year?
- MySQL query to select records with a particular date and time?
- MySQL query to insert current date plus specific time?
- Filter query by current date in MySQL
- Increment column value ‘ADD’ with MySQL SET clause
- Why we cannot use MySQL DATE data type along with time value?
- MySQL query to insert row with date?
- MySQL DATE_ADD() to increment a date based on the value in another column?
- MySQL query to set my auto increment column ( id ) to zero or reset the value of auto increment field?
- MySQL query to display databases sorted by creation date?
- Sort in MySQL and increment value?
- How MySQL evaluates if I store date along with time value in a column having DATE data type?
- Sort by date & time in descending order in MySQL?
- How to order by date and time in MySQL?
- MySQL query to select records with a particular date?

Advertisements