- 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
MySQL query to retrieve current date from a list of dates
Let’s say the current date is −
2019-07-22
Let us first create a table −
mysql> create table DemoTable705 (ShippingDate datetime); Query OK, 0 rows affected (0.67 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable705 values('2019-01-21 23:59:00'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable705 values('2019-07-22 00:00:30'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable705 values('2019-07-21 12:01:30'); Query OK, 1 row affected (0.44 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable705;
This will produce the following output -
+---------------------+ | ShippingDate | +---------------------+ | 2019-01-21 23:59:00 | | 2019-07-22 00:00:30 | | 2019-07-21 12:01:30 | +---------------------+ 3 rows in set (0.00 sec)
Following is the query to retrieve current date from a list of dates −
mysql> select *from DemoTable705 where date(ShippingDate)=CURDATE();
This will produce the following output -
+---------------------+ | ShippingDate | +---------------------+ | 2019-07-22 00:00:30 | +---------------------+ 1 row in set (0.00 sec)
Advertisements