How do I get the creation date of a MySQL table?

MySQLMySQLi Database

To get the creation date of MySQL table, use the information_schema. The syntax is as follows −

SELECT create_time FROM INFORMATION_SCHEMA.TABLES
   WHERE table_schema = 'yourDatabaseName’
   AND table_name = 'yourTableName';

Apply the above syntax for your database and the table name. Here I am using the database ‘business’ and table name is ‘student’. The query is as follows −

mysql> SELECT create_time FROM INFORMATION_SCHEMA.TABLES
   -> WHERE table_schema = 'business'
   -> AND table_name = 'student';

The following is the output displaying the creation time of a table −

+---------------------+
| CREATE_TIME         |
+---------------------+
| 2018-10-01 12:26:57 |
+---------------------+
1 row in set (0.12 sec)

Let us see another example and create a table from scratch.

mysql> create table DateAsStringDemo
   -> (
   -> YourDateTime datetime
   -> );
Query OK, 0 rows affected (0.57 sec)

I have just created a table and my current date time is as follows −

mysql> select now();

The following is the output −

+---------------------+
| now()               |
+---------------------+
| 2018-11-26 18:12:29 |
+---------------------+
1 row in set (0.00 sec)

Now you can check the creation time of the above table, which will give the date 2018-11-26.

The query is as follows −

mysql> SELECT create_time FROM INFORMATION_SCHEMA.TABLES
   -> WHERE table_schema = 'test'
   -> AND table_name = 'DateAsStringDemo';

The following is the output −

+---------------------+
| CREATE_TIME         |
+---------------------+
| 2018-11-26 18:01:44 |
+---------------------+
1 row in set (0.00 sec)
raja
Published on 24-Dec-2018 07:27:52
Advertisements