How to search a record by date in MySQL table?

MySQLMySQLi Database

Suppose we have a table ‘Order123’ having 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 how many orders received on a particular date say 25th June 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)

Suppose we have stored the OrderDate with time as well then with the help of following query we can get the specified output −

mysql> Select ProductName, Quantity from Order123 where date(OrderDate) = '2017-05-25';
raja
Published on 19-Feb-2018 10:46:35
Advertisements