Which one should I use? The datetime or timestamp data type in MySQL?

MySQLMySQLi Database

Timestamp is a data type in MySQL and works for different time zone. It is also used for date and time purpose To understand the concept, we need to create a table.

Creating a table

mysql> CREATE table TimeStampDemo
-> (
-> MyDataTime timestamp
-> );
Query OK, 0 rows affected (0.57 sec)

After creating the table, we will insert a record with the help of INSERT command.

Inserting records

mysql> INSERT into TimeStampDemo values (now());
Query OK, 1 row affected (0.12 sec)

After inserting a record, we can display the records with the help of SELECT statement.

Displaying records

mysql> SELECT * from TimeStampDemo;

After executing the above query, we will get the following output

| MyDataTime          |
| 2018-10-11 17:30:38 |
1 row in set (0.00 sec)
Updated on 25-Jun-2020 08:23:42