
- 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
What is the data type for unix_timestamp in MySQL?
The best data type for unix_timestamp in MySQL is integer. The integer data type is as follows
int(11);
The integer data type is useful for condition checking like ( > ,<= ) and indexing. The return type of unix_timestamp is an integer.
However, let us see what we get as UNIX Timestamp, when we convert datetime to timestamp.
To understand the above concept, let us first create a table. The query to create a table is as follows
mysql> create table UnixTime -> ( -> DueTime datetime -> ); Query OK, 0 rows affected (0.55 sec)
Insert records in the form of date using insert command. The query is as follows
mysql> insert into UnixTime values(now()); Query OK, 1 row affected (0.15 sec) mysql> insert into UnixTime values('2010-10-14'); Query OK, 1 row affected (0.15 sec) mysql> insert into UnixTime values('2020-09-24'); Query OK, 1 row affected (0.15 sec)
Let us now display all records from the table using select command. The query is as follows
mysql> select *from UnixTime;
The following is the output
+---------------------+ | DueTime | +---------------------+ | 2018-12-19 10:07:11 | | 2010-10-14 00:00:00 | | 2020-09-24 00:00:00 | +---------------------+ 3 rows in set (0.00 sec)
Let us see the query to convert datetime to UNIX timestamp
mysql> select unix_timestamp(DueTime) as Output from UnixTime;
The following is the output
+------------+ | Output | +------------+ | 1545194231 | | 1286994600 | | 1600885800 | +------------+ 3 rows in set (0.00 sec)
- Related Articles
- Convert MySQL timestamp to UNIX Timestamp?
- What is the difference between MySQL DATETIME and TIMESTAMP data type?
- How to convert from Unix timestamp to MySQL timestamp value?
- Convert MM/DD/YY to Unix timestamp in MySQL?
- Convert UNIX timestamp into human readable format in MySQL?
- 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 dd/mm/yyyy string to Unix timestamp in MySQL?
- Which one should I use? The datetime or timestamp data type in MySQL?
- What is BLOB data type in MySQL?
- What is TEXT data type in MySQL?
- How to get the Unix timestamp in C#
- What is MySQL ENUM data type? What are the advantages to use ENUM data type?
- Which MySQL data type is used for long decimal?

Advertisements