
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
Select Rows in MySQL That Are 1 Day From Current Date
To get data greater than equal to 1 day from the current date, use the concept of INTERVAL in MySQL.
The current date is as follows −
mysql> select curdate(); +------------+ | curdate() | +------------+ | 2019-11-29 | +------------+ 1 row in set (0.00 sec)
We will first create a table −
mysql> create table DemoTable1806 ( DueDate datetime ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1806 values('2019-11-28'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1806 values('2019-11-29'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1806 values('2019-11-30'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1806 values('2019-11-25'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1806;
This will produce the following output −
+---------------------+ | DueDate | +---------------------+ | 2019-11-28 00:00:00 | | 2019-11-29 00:00:00 | | 2019-11-30 00:00:00 | | 2019-11-25 00:00:00 | +---------------------+ 4 rows in set (0.00 sec)
Here is the query to select rows which is >=1 day from the current date
mysql> select * from DemoTable1806 where DueDate >= now() - INTERVAL 1 DAY;
This will produce the following output −
+---------------------+ | DueDate | +---------------------+ | 2019-11-29 00:00:00 | | 2019-11-30 00:00:00 | +---------------------+ 2 rows in set (0.00 sec)
Advertisements