Can we use current_date() for table with column timestamp default in MySQL?

MySQLMySQLi Database

Use the CURRENT_TIMESTAMP instead of current_date() in MySQL for timestamp default current_date. Let us first create a table. Following is the query −

mysql> create table defaultCurrent_DateDemo
   -> (
   -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   -> StudentName varchar(20),
   -> StudentAdmissionDate timestamp default CURRENT_TIMESTAMP
   -> );
Query OK, 0 rows affected (0.55 sec)

Following is the query to insert some records in the table using insert command −

mysql> insert into defaultCurrent_DateDemo(StudentName) values('Larry');
Query OK, 1 row affected (0.52 sec)

mysql> insert into defaultCurrent_DateDemo(StudentName,StudentAdmissionDate)
values('Chris','2019-01-31');
Query OK, 1 row affected (0.18 sec)

Following is the query to display all records from the table using select statement −

mysql> select *from defaultCurrent_DateDemo;

This will produce the following output −

+-----------+-------------+----------------------+
| StudentId | StudentName | StudentAdmissionDate |
+-----------+-------------+----------------------+
| 1         | Larry       | 2019-04-02 19:38:19  |
| 2         | Chris       | 2019-01-31 00:00:00  |
+-----------+-------------+----------------------+
2 rows in set (0.00 sec)
raja
Published on 15-Apr-2019 12:24:57
Advertisements