
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
Advertisements