
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Fetch Date Record That Equals Today in MySQL
For this, compare the date records with the current date using the CURDATE() method. Let us first create a table −
mysql> create table DemoTable ( RegistrationLastDate datetime ); Query OK, 0 rows affected (0.61 sec)
Let’s say the current date is −
2019-09-03
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2019-08-01'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2019-09-03 9:50:56'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('2019-09-03'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('2019-09-02'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('2019-09-02 9:50:00'); Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----------------------+ | RegistrationLastDate | +----------------------+ | 2019-08-01 00:00:00 | | 2019-09-03 09:50:56 | | 2019-09-03 00:00:00 | | 2019-09-02 00:00:00 | | 2019-09-02 09:50:00 | +----------------------+ 5 rows in set (0.00 sec)
Following is the query to fetch data record that equals today. Here, we are comparing all the records with the current date using the CURDATE() method −
mysql> select *from DemoTable where DATE(RegistrationLastDate)=curdate();
This will produce the following output −
+----------------------+ | RegistrationLastDate | +----------------------+ | 2019-09-03 09:50:56 | | 2019-09-03 00:00:00 | +----------------------+ 2 rows in set (0.01 sec)
Advertisements