Home > Database > Mysql Tutorial > How to search records by date in MySQL table?

How to search records by date in MySQL table?

WBOY
Release: 2023-09-09 08:53:13
forward
654 people have browsed it

How to search records by date in MySQL table?

Suppose we have a table "Order123" which contains ProductName, Quantity and OrderDate columns as follows -

mysql> Select * from Order123;
+-------------+----------+------------+
| ProductName | Quantity | OrderDate  |
+-------------+----------+------------+
| A           | 100      | 2017-05-25 |
| B           | 105      | 2017-05-25 |
| C           | 55       | 2017-05-25 |
| D           | 250      | 2017-05-26 |
| E           | 500      | 2017-05-26 |
| F           | 500      | 2017-05-26 |
| G           | 500      | 2017-05-27 |
| H           | 1000     | 2017-05-27 |
+-------------+----------+------------+
8 rows in set (0.00 sec)
Copy after login

Now if we want to search on a specific date like June 25, 2017), then it can be done as follows-

mysql> Select ProductName, Quantity from Order123 where OrderDate = '2017-05-25';
+-------------+----------+
| ProductName | Quantity |
+-------------+----------+
| A           | 100      |
| B           | 105      |
| C           | 55       |
+-------------+----------+
3 rows in set (0.00 sec)
Copy after login

Assuming that we also store the OrderDate and time, then with the help of the following query, we can get the specified output-

mysql> Select ProductName, Quantity from Order123 where date(OrderDate) = '2017-05-25';
Copy after login

The above is the detailed content of How to search records by date in MySQL table?. 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