Home  >  Article  >  Database  >  How to use MySQL date functions in WHERE clause?

How to use MySQL date functions in WHERE clause?

WBOY
WBOYforward
2023-08-24 22:45:021132browse

How to use MySQL date functions in WHERE clause?

By using the WHERE clause with any MySQL date function, the query will filter rows based on the conditions provided in the WHERE clause. To understand it, consider the following data from 'Collegedetail' table

mysql> Select * from Collegedetail;
+------+---------+------------+
| ID   | Country | Estb       |
+------+---------+------------+
| 111  | INDIA   | 2010-05-01 |
| 130  | INDIA   | 1995-10-25 |
| 139  | USA     | 1994-09-25 |
| 1539 | UK      | 2001-07-23 |
| 1545 | Russia  | 2010-07-30 |
+------+---------+------------+
5 rows in set (0.00 sec)

Now, suppose we want to get the details of only those colleges that were established in 2010, then we can use WHERE with YEAR() function The following query for clause:

mysql> Select * from Collegedetail WHERE YEAR(Estb) = '2010';
+------+---------+------------+
| ID   | Country | Estb       |
+------+---------+------------+
| 111  | INDIA   | 2010-05-01 |
| 1545 | Russia  | 2010-07-30 |
+------+---------+------------+
2 rows in set (0.07 sec)

The above is the detailed content of How to use MySQL date functions in WHERE clause?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete