- 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
Display records from the current date till rest of the same month in MySQL?
Let us first create a table −
mysql> create table DemoTable ( BookingDate date ); Query OK, 0 rows affected (0.67 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2019-09-21'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('2018-09-10'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('2019-09-10'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2019-09-08'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2016-09-18'); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------------+ | BookingDate | +-------------+ | 2019-09-21 | | 2018-09-10 | | 2019-09-10 | | 2019-09-08 | | 2016-09-18 | +-------------+ 5 rows in set (0.00 sec)
Following is the query from current date till rest of the month in MySQL −
mysql> select *from DemoTable where BookingDate between curdate() and last_day(curdate());
This will produce the following output −
+-------------+ | BookingDate | +-------------+ | 2019-09-21 | | 2019-09-10 | | 2019-09-08 | +-------------+ 3 rows in set (0.01 sec)
Advertisements