

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert MM/DD/YY to Unix timestamp in MySQL?
To convert MM/DD/YY to UNIX timestamp, you can use the below syntax −
select UNIX_TIMESTAMP(str_to_date(yourColumnName,'%m/%d/%Y')) from yourTableName;
Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, dateConvertToUnix varchar(100) ); Query OK, 0 rows affected (0.58 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(dateConvertToUnix) values('01/10/2001'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(dateConvertToUnix) values('03/31/2010'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(dateConvertToUnix) values('12/31/2016'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(dateConvertToUnix) values('04/27/2019'); Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable;
This will produce the following output −
+----+-------------------+ | Id | dateConvertToUnix | +----+-------------------+ | 1 | 01/10/2001 | | 2 | 03/31/2010 | | 3 | 12/31/2016 | | 4 | 04/27/2019 | +----+-------------------+ 4 rows in set (0.00 sec)
Following is the query to convert MM/DD/YY to UNIX timestamp −
mysql> select UNIX_TIMESTAMP(str_to_date(dateConvertToUnix,'%m/%d/%Y')) from DemoTable;
This will produce the following output −
+-----------------------------------------------------------+ | UNIX_TIMESTAMP(str_to_date(dateConvertToUnix,'%m/%d/%Y')) | +-----------------------------------------------------------+ | 979065000 | | 1269973800 | | 1483122600 | | 1556303400 | +-----------------------------------------------------------+ 4 rows in set (0.00 sec)
- Related Questions & Answers
- MySQL - Convert YYYY-MM-DD to UNIX timestamp
- Convert dd/mm/yyyy string to Unix timestamp in MySQL?
- How to convert MM/YY to YYYY-MM-DD in MYSQL?
- How to convert date YYYYMMDD to YY-MM-DD in MySQL query?
- How to convert MM/YY to YYYY-MM-DD with a specific day in MySQL?
- Convert MySQL timestamp to UNIX Timestamp?
- How to convert from Unix timestamp to MySQL timestamp value?
- Format date with SimpleDateFormat('MM/dd/yy') in Java
- How to convert MySQL datetime to Unix timestamp?
- MySQL query to convert YYYY-MM-DD to DD Month, YYYY date format
- Convert MySQL Unix-Timestamp format to date format?
- MySQL date format to convert dd.mm.yy to YYYY-MM-DD?
- Convert MySQL date format from yyyy-mm-ddThh:mm:ss.sssZ to yyyy-mm-dd hh:mm:ss ?
- Convert UNIX timestamp into human readable format in MySQL?
- Converting date type SYDATUM in a format like MM/DD/YY in SAP ABAP
Advertisements