
- 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 compare DateTime Column with only Date not time in MySQL?
To compare DateTime column with only Date, you need to use the Date() method. Following is the syntax. Below, you need to date in the 'yourDateValue':
select *from yourTableName where Date(yourColumnName)='yourDateValue';
Let us first create a table:
mysql> create table DemoTable ( ArrivalTime datetime ); Query OK, 0 rows affected (0.74 sec)
Following is the query to insert some records in the table using insert command:
mysql> insert into DemoTable values('2019-01-31 02:34:56'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('2019-04-09 18:20:58'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2019-05-11 19:45:23'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2019-02-03 21:10:02'); Query OK, 1 row affected (0.16 sec)
Following is the query to display records from the table using select command:
mysql> select *from DemoTable;
This will produce the following output with date and time record:
+---------------------+ | ArrivalTime | +---------------------+ | 2019-01-31 02:34:56 | | 2019-04-09 18:20:58 | 2019-05-11 19:45:23 | | 2019-02-03 21:10:02 | +---------------------+ 4 rows in set (0.00 sec)
Following is the query to compare only date not time. Here, we are comparing the date:
mysql> select *from DemoTable where Date(ArrivalTime)='2019-04-09';
This will produce the following output:
+---------------------+ | ArrivalTime | +---------------------+ | 2019-04-09 18:20:58 | +---------------------+ 1 row in set (0.00 sec)
- Related Articles
- How to split the datetime column into date and time and compare individually in MySQL?
- How to select only MySQL date from datetime column?
- How to combine date and time from different MySQL columns to compare with the entire DateTime?
- Compare DATE string with string from MySQL DATETIME field?
- How to extract from datetime column in MySQL by comparing only date and ignoring whitespace?
- How to convert JS date time to MySQL datetime?
- How to add time in a MySQL column set with type DATETIME?
- How to part DATE and TIME from DATETIME in MySQL?
- How to compare only date part without comparing time in JavaScript?
- Get only the date from datetime in MySQL?
- Compare only day and month with date field in MySQL?
- Create DATETIME from DATE and TIME in MySQL?
- How to compare the first date and the last date from a MySQL column with date records?
- How to compare Python DateTime with Javascript DateTime?
- MySQL query to get current datetime and only current date

Advertisements