- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Change a MySQL Column datatype from text to timestamp?
To change a MySQL column datatype from text to timestamp, you need to use ALTER command.
The syntax is as follows
ALTER TABLE yourTableName MODIFY COLUMN yourColumnName TIMESTAMP;
To understand the above syntax, let us create a table.
The query to create a table is as follows
mysql> create table textTotimestampdemo - > ( - > Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, - > Source text - > ); Query OK, 0 rows affected (0.44 sec)
Here is the description of table using DESC command.
The syntax is as follows
DESC yourTableName;
The query is as follows
mysql> desc textTotimestampdemo;
The following is the output
+--------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------+---------+------+-----+---------+----------------+ | Id | int(11) | NO | PRI | NULL | auto_increment | | Source | text | YES | | NULL | | +--------+---------+------+-----+---------+----------------+ 2 rows in set (0.04 sec)
Now change the column text to timestamp with the help of the following query
mysql> alter table textTotimestampdemo modify column Source TIMESTAMP; Query OK, 0 rows affected (1.25 sec) Records: 0 Duplicates: 0 Warnings: 0
Now check the description of the table once again.
The query is as follows
mysql> desc textTotimestampdemo;
The following is the output
+--------+-----------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------+-----------+------+-----+---------+----------------+ | Id | int(11) | NO | PRI | NULL | auto_increment | | Source | timestamp | YES | | NULL | | +--------+-----------+------+-----+---------+----------------+ 2 rows in set (0.00 sec)
Look at the column Source above, the datatype has been changed from text to timestamp.
- Related Articles
- For timestamp, which datatype is used in MySQL?
- Change the file extension in the text column in MySQL?
- How to convert from Unix timestamp to MySQL timestamp value?
- How to change the datatype of a column in an existing table using JDBC API?
- Change the column name from StudentName to FirstName in MySQL?
- MySQL query to select date from timestamp?
- Change the column name from a MySQL table with Student record?
- Combine date and time column into a timestamp in MySQL?
- How to change MySQL column definition?
- Convert MySQL timestamp to UNIX Timestamp?
- How to select date from timestamp in MySQL?
- Get first date from timestamp in MySQL group by another column with duplicate value
- Change a MySQL column to have NOT NULL constraint
- How do I alter table column datatype on more than 1 column at a time in MySql?
- How to add a “created at” column in a table to set the timestamp in MySQL?

Advertisements