- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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)
- Related Articles
- Select a column if condition is met in MySQL to fetch records from current date and current date + 1
- Fetch date records comparing with the current date’s day and month in MySQL
- MySQL query to fetch date records greater than the current date after adding days with INTERVAL?
- MySQL time period query to fetch date records from interval of 14 weeks from current date?
- Fetch student records whose result declared 12 days before the current date in MYSQL
- Fetch records from interval of past 3 days from current date in MySQL and add the corresponding records
- MySQL query to fetch the latest date from a table with date records
- Comparison of varchar date records from the current date in MySQL
- Order date records and fetch the 2nd ordered record in MySQL
- UNIX_TIMESTAMP with date in MySQL query to fetch records after a specific date in different format?
- Set a MySQL field with the current date (UNIX_TIMESTAMP(now))
- MySQL query to get the current date records wherein one of the columns displays current date
- How to insert current date/ time using now() in a field with MySQL?
- How to get the difference between date records and the current date in MySQL?
- Condition to check for due date and current date records in MySQL where clause

Advertisements