
- 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 use CONTAINS() with CURDATE in MySQL?
For this, you can use CONCAT() with CURDATE().There is no function with the name CONTAINS() in MySQL.
Let us first get the current date. The current date is as follows −
mysql> select curdate();
This will produce the following output −
+------------+ | curdate() | +------------+ | 2019-11-28 | +------------+ 1 row in set (0.00 sec)
We will now create a table −
mysql> create table DemoTable1803 ( Name varchar(20), JoiningYear varchar(20) ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1803 values('Chris','2020/2017'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1803 values('David','2017/2018'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1803 values('Adam','2018/2019'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1803;
This will produce the following output −
+-------+-------------+ | Name | JoiningYear | +-------+-------------+ | Chris | 2020/2017 | | David | 2017/2018 | | Adam | 2018/2019 | +-------+-------------+ 3 rows in set (0.00 sec)
Here is the query
mysql> select * from DemoTable1803 where JoiningYear like concat('%', YEAR(CURDATE()), '%');
This will produce the following output −
+------+-------------+ | Name | JoiningYear | +------+-------------+ | Adam | 2018/2019 | +------+-------------+ 1 row in set (0.00 sec)
- Related Articles
- How can I use INTERVAL keyword with MySQL NOW() and CURDATE() functions?
- How to get the previous day with MySQL CURDATE()?
- How MySQL behaves when we use INTERVAL of time unit with CURDATE() function?
- How to make MySQL's NOW() and CURDATE() functions use UTC?
- CURDATE () vs NOW() in MySQL
- Change the curdate() (current date) format in MySQL
- How to Use Go with MySQL?
- How to correctly use WITH ROLLUP in MySQL?
- How to use contains() in android CopyOnWriteArrayList?
- How to use contains() in android CopyOnWriteArraySet?
- How to use contains() in android LinkedBlockingDeque?
- How to use contains() in android PriorityBlockingQueue?
- How to use Contains() function in Golang?
- How to use contains () in Android text view?
- How to use MySQL VIEW with WHERE clause?

Advertisements