
- 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
MySQL - Convert YYYY-MM-DD to UNIX timestamp
To convert date to UNIX timestamp, use UNIX_TIMESTAMP() in MySQL −
mysql> create table DemoTable1997 ( DueDate date ); Query OK, 0 rows affected (0.58 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1997 values('2018-10-11'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1997 values('2019-12-21'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1997 values('2017-01-31'); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1997;
This will produce the following output −
+------------+ | DueDate | +------------+ | 2018-10-11 | | 2019-12-21 | | 2017-01-31 | +------------+ 3 rows in set (0.00 sec)
Here is the query to convert YYYY-MM-DD to unix timestamp −
mysql> select unix_timestamp(cast(DueDate as date)) as Result from DemoTable1997;
This will produce the following output −
+------------+ | Result | +------------+ | 1539196200 | | 1576866600 | | 1485801000 | +------------+ 3 rows in set (0.00 sec)
- Related Articles
- Convert dd/mm/yyyy string to Unix timestamp in MySQL?
- Convert MM/DD/YY to Unix timestamp in MySQL?
- MySQL query to convert YYYY-MM-DD to DD Month, YYYY date format
- Convert MySQL date format from yyyy-mm-ddThh:mm:ss.sssZ to yyyy-mm-dd hh:mm:ss ?
- How to convert MM/YY to YYYY-MM-DD in MYSQL?
- MySQL date format to convert dd.mm.yy to YYYY-MM-DD?
- How to convert MM/YY to YYYY-MM-DD with a specific day in MySQL?
- Convert MySQL timestamp to UNIX Timestamp?
- MySQL date format DD/MM/YYYY select query?
- How to convert Python date string mm/dd/yyyy to datetime?
- How to Convert YYYY-MM-DD to Standard Date in Excel?
- How to insert mm/dd/yyyy format dates in MySQL?
- How to parse Date from String in the format: dd/MM/yyyy to dd/MM/yyyy in java?
- Get date format DD/MM/YYYY with MySQL Select Query?
- How to convert from Unix timestamp to MySQL timestamp value?

Advertisements