
- 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
Select timestamp as date string in MySQL?
To select timestamp as date string in MySQL, the syntax is as follows −
select FROM_UNIXTIME(yourColumnName, '%Y-%m-%d %H:%i:%s') from yourTableName;
To understand the above syntax, let us create a table. The query to create a table is as follows −
mysql> create table select_timestampDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ArrivalDateTime int -> ); Query OK, 0 rows affected (0.62 sec)
Insert some records in the table using insert command. The query is as follows −
mysql> insert into select_timestampDemo(ArrivalDateTime) values(1546499730); Query OK, 1 row affected (0.18 sec) mysql> insert into select_timestampDemo(ArrivalDateTime) values(1546210820); Query OK, 1 row affected (0.23 sec) mysql> insert into select_timestampDemo(ArrivalDateTime) values(1496363157); Query OK, 1 row affected (0.29 sec)
Now you can display all records from the table using select statement. The query is as follows −
mysql> select *from select_timestampDemo;
Here is the output −
+----+-----------------+ | Id | ArrivalDateTime | +----+-----------------+ | 1 | 1546499730 | | 2 | 1546210820 | | 3 | 1496363157 | +----+-----------------+ 3 rows in set (0.00 sec)
The following is the query to select timestamp as a date string −
mysql> select FROM_UNIXTIME(ArrivalDateTime, '%Y-%m-%d %H:%i:%s') from select_timestampDemo;
Here is the output −
+-----------------------------------------------------+ | FROM_UNIXTIME(ArrivalDateTime, '%Y-%m-%d %H:%i:%s') | +-----------------------------------------------------+ | 2019-01-03 12:45:30 | | 2018-12-31 04:30:20 | | 2017-06-02 05:55:57 | +-----------------------------------------------------+ 3 rows in set (0.00 sec)
- Related Articles
- How to select date from timestamp in MySQL?
- Get timestamp date range with MySQL Select?
- MySQL query to select date from timestamp?
- Convert date string to timestamp in Python
- Get only the date in timestamp in MySQL?
- Display Timestamp before the current date in MySQL
- Display only date from timestamp value in MySQL
- Select entries with timestamp after X time in MySQL
- MySQL Select where timestamp is in the current hour?
- Set current date and time to timestamp in MySQL
- Convert MySQL Unix-Timestamp format to date format?
- Combine date and time column into a timestamp in MySQL?
- How to search for a date in MySQL timestamp field?
- Convert string (varchar) to timestamp format in MySQL?
- How to Insert custom date into MySQL timestamp field?

Advertisements