
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to convert timestamp to datetime in MySQL?
We can convert the timestamp to date time with the help of FROM_UNIXTIME() function. Let us see an example. First, we will create a table with column of int type. Then we convert it to timestamp and again into date time.
Creating a table with integer type.
mysql> create table TimestamptoDateDemo -> ( -> YourTimeStamp int(11) -> ); Query OK, 0 rows affected (0.57 sec)
Inserting records into the table.
mysql> insert into TimestamptoDateDemo values(1389453221); Query OK, 1 row affected (0.23 sec)
To display all the records.
mysql> select *from TimestamptoDateDemo;
The following is the output.
+---------------+ | YourTimeStamp | +---------------+ | 1389453221 | +---------------+ 1 row in set (0.00 sec)
Syntax to convert it into timestamp.
SELECT from_unixtime(yourColumnName) from yourTableName;
The following is the implementation.
mysql>select from_unixtime(YourTimeStamp) from TimestamptoDateDemo;
Here is the output.
+------------------------------+ | from_unixtime(YourTimeStamp) | +------------------------------+ | 2018-09-11 20:43:41 | +------------------------------+ 1 row in set (0.04 sec)
Syntax to convert the above timestamp to datetime.
select from_unixtime(YourColumnName, '%Y %D %M %h:%i:%s') from yourTableName;
The following is the output that shows the datetime.
+---------------------------------------------------+ | from_unixtime(YourTimeStamp, '%Y %D %M %h:%i:%s') | +---------------------------------------------------+ | 2018 11th September 08:43:41 | +---------------------------------------------------+ 1 row in set (0.03 sec)
- Related Articles
- How to convert MySQL datetime to Unix timestamp?
- How to convert TimeStamp to DateTime in Kotlin?\n
- How to convert timestamp string to datetime object in Python?
- How to convert JavaScript datetime to MySQL datetime?
- Convert MySQL timestamp to UNIX Timestamp?
- How to convert from Unix timestamp to MySQL timestamp value?
- How do I convert a datetime to a UTC timestamp in Python?
- How to convert DateTime to a number in MySQL?
- Convert INT to DATETIME in MySQL?
- How to convert char field to datetime field in MySQL?
- How to convert JS date time to MySQL datetime?
- Pandas - Convert a Timestamp object to a native Python datetime object
- MySQL query to convert timestamp to month?
- How to convert string to 24-hour datetime format in MySQL?
- How to convert MySQL DATETIME value to JSON format in JavaScript?

Advertisements