How to easily insert datetime in MySQL?

MySQLMySQLi Database

You can easily insert DateTime with the MySQL command line. Following is the syntax −

insert into yourTableName values(‘yourDateTimeValue’);

Let us first create a table −

mysql> create table DemoTable
(
   DateOfBirth datetime
);
Query OK, 0 rows affected (0.97 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values('1998-01-23 12:45:56');
Query OK, 1 row affected (0.26 sec)
mysql> insert into DemoTable values('2010-12-31 01:15:00');
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable values('2015-04-03 14:00:45');
Query OK, 1 row affected (0.10 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+---------------------+
| DateOfBirth         |
+---------------------+
| 1998-01-23 12:45:56 |
| 2010-12-31 01:15:00 |
| 2015-04-03 14:00:45 |
+---------------------+
3 rows in set (0.00 sec)
raja
Published on 26-Sep-2019 08:33:08
Advertisements