
- 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
How to extract from datetime column in MySQL by comparing only date and ignoring whitespace?
To extract from datetime column, you can use date() along with trim(). Here, trim() is used to remove whitespace while comparing. Let us first create a table −
mysql> create table DemoTable661(Duedate datetime); Query OK, 0 rows affected (0.57 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable661 values(' 2019-01-21 12:02:21'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable661 values(' 2019-07-11 11:55:59 '); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable661 values('2019-11-21 04:00:59 '); Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable661;
This will produce the following output −
+---------------------+ | Duedate | +---------------------+ | 2019-01-21 12:02:21 | | 2019-07-11 11:55:59 | | 2019-11-21 04:00:59 | +---------------------+ 3 rows in set (0.00 sec)
Following is the query to extract date from datetime column −
mysql> select *from DemoTable661 where trim(date(Duedate))='2019-07-11';
This will produce the following output −
+---------------------+ | Duedate | +---------------------+ | 2019-07-11 11:55:59 | +---------------------+ 1 row in set (0.00 sec)
- Related Articles
- How to select only MySQL date from datetime column?
- How to compare DateTime Column with only Date not time in MySQL?
- Comparing dates in MySQL ignoring time portion of a DateTime field?
- Get only the date from datetime in MySQL?
- Extracting only date from datetime field in MySQL and assigning it to PHP variable?
- How to part DATE and TIME from DATETIME in MySQL?
- MySQL query to get current datetime and only current date
- How to extract date from string in MySQL?
- How to extract only the month and day from a datetime object in Python?
- How to get only Date portion from DateTime object in C#?
- Create DATETIME from DATE and TIME in MySQL?
- How to extract column name and type from MySQL?
- How to split the datetime column into date and time and compare individually in MySQL?
- MySQL query to display only the column values with corresponding column having whitespace
- MySQL Query to convert from datetime to date?

Advertisements