
- 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
Convert MySQL Unix-Timestamp format to date format?
To achieve this, the following is the syntax
select date_format(from_unixtime(yourColumnName),'%b %d, %Y %l:%i %p PDT') from yourTableName;
To understand the above syntax, let us create a table. The query to create a table is as follows
mysql> create table unixTimeStampFormatDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> MyTimeStampValue bigint -> ); Query OK, 0 rows affected (0.59 sec)
Insert some records in the table using insert command. The query is as follows −
mysql> insert into unixTimeStampFormatDemo(MyTimeStampValue) values(1334428200); Query OK, 1 row affected (0.20 sec) mysql> insert into unixTimeStampFormatDemo(MyTimeStampValue) values(1513881000); Query OK, 1 row affected (0.15 sec) mysql> insert into unixTimeStampFormatDemo(MyTimeStampValue) values(1542738600); Query OK, 1 row affected (0.14 sec) mysql> insert into unixTimeStampFormatDemo(MyTimeStampValue) values(1551637800); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement. The query is as follows −
mysql> select *from unixTimeStampFormatDemo;
The following is the output
+----+------------------+ | Id | MyTimeStampValue | +----+------------------+ | 1 | 1334428200 | | 2 | 1513881000 | | 3 | 1542738600 | | 4 | 1551637800 | +----+------------------+ 4 rows in set (0.00 sec)
Here is the query to convert MySQL Unix-Timestamp Format to datetime
mysql> select date_format(from_unixtime(MyTimeStampValue),'%b %d, %Y %l:%i %p PDT') from unixTimeStampFormatDemo;
The following is the output
+-----------------------------------------------------------------------+ | date_format(from_unixtime(MyTimeStampValue),'%b %d, %Y %l:%i %p PDT') | +-----------------------------------------------------------------------+ | Apr 15, 2012 12:00 AM PDT | | Dec 22, 2017 12:00 AM PDT | | Nov 21, 2018 12:00 AM PDT | | Mar 04, 2019 12:00 AM PDT | +-----------------------------------------------------------------------+ 4 rows in set (0.00 sec)
- Related Articles
- Convert UNIX timestamp into human readable format in MySQL?
- Convert MySQL timestamp to UNIX Timestamp?
- Unix date format in Java
- Convert string (varchar) to timestamp format in MySQL?
- How to convert Python date format to 10-digit date format for mysql?
- Convert VARCHAR data to MySQL date format?
- How to convert US date format to MySQL format in INSERT query?
- How to convert Python date to Unix timestamp?
- How to convert a date format in MySQL?
- How to convert from Unix timestamp to MySQL timestamp value?
- Convert VARCHAR Date to a different format in MySQL?
- Format MySQL date and convert to year-month-day
- How to correctly convert a date format into a MySQL date?
- How to convert MySQL datetime to Unix timestamp?
- MySQL date format to convert dd.mm.yy to YYYY-MM-DD?

Advertisements