- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to search a record by date in MySQL table?
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';
Advertisements
To Continue Learning Please Login
Login with Google