
- 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
Extract Numeric Date Value from Date Format in MySQL?
For this, use UNIX_TIMESTAMP(). Following is the syntax −
select UNIX_TIMESTAMP(STR_TO_DATE(yourColumnName, "%d-%b-%y")) as anyAliasName from yourTableName;
Let us create a table −
mysql> create table demo34 −> ( −> datevalue varchar(40) −> ); Query OK, 0 rows affected (1.51 sec)
Insert some records into the table with the help of insert command −
mysql> insert into demo34 values('31−Jan−19'); Query OK, 1 row affected (0.13 sec) mysql> insert into demo34 values('03−Mar−21'); Query OK, 1 row affected (0.12 sec) mysql> insert into demo34 values('13−Jun−20'); Query OK, 1 row affected (0.11 sec)
Display records from the table using select statement −
mysql> select *from demo34;
This will produce the following output −
+-----------+ | datevalue | +-----------+ | 31−Jan−19 | | 03−Mar−21 | | 13−Jun−20 | +-----------+ 3 rows in set (0.00 sec)
Following is the query to extract numeric date value from date format −
mysql> select UNIX_TIMESTAMP(STR_TO_DATE( datevalue, "%d-%b-%y")) as Numeric_Date from demo34;
This will produce the following output −
+--------------+ | Numeric_Date | +--------------+ | 1548873000 | | 1614709800 | | 1591986600 | +--------------+ 3 rows in set (0.00 sec)
- Related Articles
- MySQL extract year from date format?
- How to extract date from string in MySQL?
- MySQL ORDER BY Date field not in date format?
- Select date from MySQL and format to text?
- Format date value in MongoDB shell?
- How to convert Python date format to 10-digit date format for mysql?
- How to format date value in JavaScript?
- Convert MySQL Unix-Timestamp format to date format?
- Insert current date in datetime format MySQL?
- Set a specific Date Format in MySQL?
- Format date while inserting records in MySQL
- Display only date from timestamp value in MySQL
- Replace date format with MySQL STR_TO_DATE
- Format date to display month names with the entire date in MySQL?
- How to correctly convert a date format into a MySQL date?

Advertisements