How to add Date column in MySQL

Here we will see how we can add date column in MySQL table.

if you want to add new date column in existing MySQL table then we will use Alter table statement. you can read our post on how to add new column in MySQL table.

we will use the add new column statement to add date column in MySQL table which is

Alter Table table_name ADD col_nm datatype;

Date can be inserted in MySQL in two ways:

  1. Date – it will insert date only like YYYY-MM-DD.
  2. TIMESTAMP – It will insert date like YYYY-MM-DD hh:mm:ss

So, make sure how you want to insert the date data.

ADD Date Column in MySQL table

We will take example to explain how to add date column in MySQL.

mysql> Describe Dept;
+------------+-------------+------+-----+---------+-------+
| Field      | Type        | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| id         | int         | NO   | PRI | NULL    |       |
| name       | varchar(20) | YES  |     | NULL    |       |
| Dept_owner | varchar(50) | YES  |     | NULL    |       |
+------------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)

Now we will add new column Dept_Created_date

Alter Table Dept ADD Dept_Created_date DATE;

After executing above alter statement, new date column will be added in Dept table.

mysql> Describe Dept;  
+-------------------+-------------+------+-----+---------+-------+  
| Field             | Type        | Null | Key | Default | Extra |
+-------------------+-------------+------+-----+---------+-------+   
| id                | int         | NO   | PRI | NULL    |       |
| name              | varchar(20) | YES  |     | NULL    |       |
| Dept_owner        | varchar(50) | YES  |     | NULL    |       |
| Dept_Created_date | date        | YES  |     | NULL    |       |
+-------------------+-------------+------+-----+---------+-------+    
4 rows in set (0.00 sec)

After adding date column in dept table. lets update the record value

update dept set dept_created_date='2021-01-01' where id=1;

output will be

mysql> select * from dept;
+----+---------+------------+-------------------+ 
| id | name    | Dept_owner | Dept_Created_date | 
+----+---------+------------+-------------------+ 
|  1 | IT      | NULL       | 2021-01-01        |
|  2 | Faculty | NULL       | NULL              |
+----+---------+------------+-------------------+ 
2 rows in set (0.00 sec)

Date value is inserted into newly created column having date datatype.

Scroll to Top