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

How to use MySQL date functions in WHERE clause?

WBOY
Release: 2023-08-24 22:45:02
forward
1167 people have browsed it

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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template