Home > Database > Mysql Tutorial > body text

How to get the creation date of a MySQL table?

王林
Release: 2023-08-27 13:33:18
forward
1133 people have browsed it

如何获取 MySQL 表的创建日期?

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

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

Apply the above syntax to your database and table names. Here I use the database "business" and the 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';
Copy after login

The following is the output showing the table creation time -

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

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)
Copy after login

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

mysql> select now();
Copy after login

Below is the output -

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

Now you can check the creation time of the above table, it The date 2018-11-26 will be given.

The query is as follows -

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

The following is the output -

+---------------------+
| CREATE_TIME         |
+---------------------+
| 2018-11-26 18:01:44 |
+---------------------+
1 row in set (0.00 sec)
Copy after login

The above is the detailed content of How to get the creation date of a MySQL table?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!