
- 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 timestamp to UNIX Timestamp?
To convert MySQL timestamp to UNIX Timestamp, use the UNIX_TIMESTAMP(). Following is the syntax −
select unix_timestamp(yourColumnName) from yourTableName;
Let us first create a table −
mysql> create table DemoTable( Duetimestamp timestamp ); Query OK, 0 rows affected (2.66 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(now()); Query OK, 1 row affected (1.53 sec) mysql> insert into DemoTable values('2016-01-21 12:34:00'); Query OK, 1 row affected (0.73 sec) mysql> insert into DemoTable values('2018-05-01 02:00:00'); Query OK, 1 row affected (0.42 sec) mysql> insert into DemoTable values('2017-03-02 01:10:20'); Query OK, 1 row affected (10.19 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+---------------------+ | Duetimestamp | +---------------------+ | 2019-08-20 20:48:45 | | 2016-01-21 12:34:00 | | 2018-05-01 02:00:00 | | 2017-03-02 01:10:20 | +---------------------+ 4 rows in set (0.00 sec)
Following is the query to convert MySQL timestamp to UNIX Timestamp −
mysql> select unix_timestamp(Duetimestamp) from DemoTable;
This will produce the following output −
+------------------------------+ | unix_timestamp(Duetimestamp) | +------------------------------+ | 1566314325 | | 1453359840 | | 1525120200 | | 1488397220 | +------------------------------+ 4 rows in set (0.04 sec)
- Related Articles
- How to convert from Unix timestamp to MySQL timestamp value?
- How to convert MySQL datetime to Unix timestamp?
- Convert MySQL Unix-Timestamp format to date format?
- MySQL - Convert YYYY-MM-DD to UNIX timestamp
- Convert MM/DD/YY to Unix timestamp in MySQL?
- Convert dd/mm/yyyy string to Unix timestamp in MySQL?
- Convert UNIX timestamp into human readable format in MySQL?
- How to convert Python date to Unix timestamp?
- How to convert a Unix timestamp to time in JavaScript?
- How to convert unix timestamp string to readable date in Python?
- MySQL query to convert timestamp to month?
- How to convert timestamp to datetime in MySQL?
- How to get the Unix timestamp in C#
- Convert string (varchar) to timestamp format in MySQL?
- Convert DATE timestamp to return only the month name in MySQL

Advertisements