- Trending Categories
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
Calling NOW() function to fetch current date records in MySQL?
Let us first create a table −
mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ShippingDate datetime -> ); Query OK, 0 rows affected (1.16 sec)
Insert some records in the table using insert command. Consider current date “2019-06-28” −
mysql> insert into DemoTable(ShippingDate) values('2019-01-31'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(ShippingDate) values('2019-06-06'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(ShippingDate) values('2019-06-28'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(ShippingDate) values('2019-07-01'); Query OK, 1 row affected (0.16 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+----+---------------------+ | Id | ShippingDate | +----+---------------------+ | 1 | 2019-01-31 00:00:00 | | 2 | 2019-06-06 00:00:00 | | 3 | 2019-06-28 00:00:00 | | 4 | 2019-07-01 00:00:00 | +----+---------------------+ 4 rows in set (0.00 sec)
Here is the query to call NOW() function in MySQL and fetch the current date record from the table −
mysql> select *from DemoTable where Date(ShippingDate)=Date(now());
Output
This will produce the following output −
+----+---------------------+ | Id | ShippingDate | +----+---------------------+ | 3 | 2019-06-28 00:00:00 | +----+---------------------+ 1 row in set (0.00 sec)
Advertisements