
- 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
Compare date strings in MySQL
To compare date strings, use STR_TO_DATE() from MySQL.
Let us first create a table −
mysql> create table DemoTable712 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ArrivalDate varchar(100) ); Query OK, 0 rows affected (0.65 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable712(ArrivalDate) values('10.01.2019'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable712(ArrivalDate) values('11.12.2018'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable712(ArrivalDate) values('01.11.2017'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable712(ArrivalDate) values('20.06.2016'); Query OK, 1 row affected (0.23 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable712;
This will produce the following output -
+----+-------------+ | Id | ArrivalDate | +----+-------------+ | 1 | 10.01.2019 | | 2 | 11.12.2018 | | 3 | 01.11.2017 | | 4 | 20.06.2016 | +----+-------------+ 4 rows in set (0.00 sec)
Following is the query to compare date strings −
mysql> select *from DemoTable712 where str_to_date(ArrivalDate,'%d.%m.%Y')='2017-11-01';
This will produce the following output -
+----+-------------+ | Id | ArrivalDate | +----+-------------+ | 3 | 01.11.2017 | +----+-------------+ 1 row in set (0.00 sec)
- Related Articles
- How to compare date strings in Python?
- How to compare two strings which are numbers in MySQL?
- Compare date when the AdmissionDate is less than the current date in MySQL
- Compare Strings in Arduino
- Compare only day and month with date field in MySQL?
- Compare DATE string with string from MySQL DATETIME field?
- Compare two Strings in Java
- How to compare DateTime Column with only Date not time in MySQL?
- How to compare the first date and the last date from a MySQL column with date records?
- Compare two strings lexicographically in Java.
- How to compare strings in Java?
- Compare two strings lexicographically in C#
- Java Program to Compare Strings
- How do I compare strings in Java?
- Compare the two Strings lexicographically in Java

Advertisements