
- 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
Get current year in MySQL WHERE clause?
To get current year, use YEAR() along with CURDATE(). Let us first create a table −
mysql> create table DemoTable1360 -> ( -> JoiningYear int -> ) -> ; Query OK, 0 rows affected (0.51 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1360 values(1998); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1360 values(2018); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable1360 values(2016); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1360 values(2019); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1360 values(2017); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1360 values(2015); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1360;
This will produce the following output −
+-------------+ | JoiningYear | +-------------+ | 1998 | | 2018 | | 2016 | | 2019 | | 2017 | | 2015 | +-------------+ 6 rows in set (0.00 sec)
Following is the query to get current year in MySQL where clause −
mysql> select * from DemoTable1360 where JoiningYear=year(curdate());
This will produce the following output −
+-------------+ | JoiningYear | +-------------+ | 2019 | +-------------+ 1 row in set (0.00 sec)
- Related Articles
- Get all results using WHERE clause in MySQL?
- Condition to check for due date and current date records in MySQL where clause
- Using the entire expression in MySQL WHERE clause?
- Update with multiple values in MySQL WHERE clause
- How to get the current year in JavaScript?
- Get the days remaining in current year in Java
- Select last day of current year in MySQL?
- MySQL to Implementing OR operator in a WHERE clause?
- How to get the only current year in JavaScript?
- How Can we use MySQL DISTINCT clause with WHERE and LIMIT clause?
- How to use MySQL VIEW with WHERE clause?
- How to use MySQL Date functions with WHERE clause?
- Can we use WHERE clause inside MySQL CASE statement?
- Can we fetch multiple values with MySQL WHERE Clause?
- Java Program to get current date, year and month

Advertisements