 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
Can we use INTERVAL keyword while inserting date records in a MySQL table?
Yes, we can use INTERVAL while inserting data records. Let us first create a table −
mysql> create table DemoTable ( ArrivalTime datetime ); Query OK, 0 rows affected (0.52 sec)
Insert some records in the table using insert command. Here, we are using INTERVAL keyword for incrementing the date records while inserting −
mysql> insert into DemoTable values(date_add(now(), interval 4 hour)); Query OK, 1 row affected (0.41 sec) mysql> insert into DemoTable values(date_add('2016-01-31 10:40:50', interval 2 hour)); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(date_add('2015-05-01 12:00:00', interval 1 hour)); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable values(date_add('2017-12-04 08:00:00', interval 9 hour)); Query OK, 1 row affected (0.16 sec) Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+---------------------+ | ArrivalTime | +---------------------+ | 2019-08-13 01:50:10 | | 2016-01-31 12:40:50 | | 2015-05-01 13:00:00 | | 2017-12-04 17:00:00 | +---------------------+ 4 rows in set (0.00 sec)
Advertisements
 