
- 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 query to return the entire date and time based on a string and format
Let us first create a table −
mysql> create table DemoTable -> ( -> AdmissionDate varchar(100) -> ); Query OK, 0 rows affected (0.66 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Wed, 19 Jun 2019 04:10:20'); Query OK, 1 row affected (0.22 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+---------------------------+ | AdmissionDate | +---------------------------+ | Wed, 19 Jun 2019 04:10:20 | +---------------------------+ 1 row in set (0.00 sec)
Following is the to return date and time based on string and format −
mysql> SELECT STR_TO_DATE(AdmissionDate, '%a, %d %b %Y %H:%i:%s EDT') from DemoTable;
Output
This will produce the following output −
+---------------------------------------------------------+ | STR_TO_DATE(AdmissionDate, '%a, %d %b %Y %H:%i:%s EDT') | +---------------------------------------------------------+ | 2019-06-19 04:10:20 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
- Related Articles
- Return query based on date in MongoDB?
- Format date in MySQL to return MonthName and Year?
- Format date to display month names with the entire date in MySQL?
- MySQL query to select records with a particular date and time?
- MySQL query to extract only the day instead of entire date
- MySQL query with two boolean conditions to extract date based on hour?
- Set format specifier in MySQL STR_TO_DATE() and convert string to date
- MySQL query to append a number of stars based on string length?
- How to combine date and time from different MySQL columns to compare with the entire DateTime?
- How to convert US date format to MySQL format in INSERT query?
- Format Date and Time in Perl
- How to use together the date and time format characters in MySQL DATE_FORMAT() function?
- MySQL query to extract time in a format without seconds
- How to format date and time in android?
- MySQL date format DD/MM/YYYY select query?

Advertisements