Select*fromOrder123;+-------------+--------- -+----------------+|ProductName|Quantity|OrderDate |+-------------+----------+-- ----------+|A &"/> Select*fromOrder123;+-------------+--------- -+----------------+|ProductName|Quantity|OrderDate |+-------------+----------+-- ----------+|A &">
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)
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)
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';
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!