![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
Get the first and last date of next month in MySQL?
You can get the first and last date of next month using date_add() function from MySQL.
The syntax is as follows -
select date_sub( last_day( date_add(now(), interval anyIntervalTime) ), interval day( last_day( date_add(now(), interval anyIntervalTime) ) )-1 DAY ) as anyVariableName, last_day ( date_add(now(), anyIntervalTime) ) as anyVariableName;
Implement the above syntax to get the first and last date of next month using interval 1 month in date_add() function. The query is as follows.
mysql> select -> date_sub( -> last_day( -> date_add(now(), interval 1 month) -> ), -> interval day( -> last_day( -> date_add(now(), interval 1 month) -> ) -> )-1 DAY -> ) as firstDayOfNextMonth, -> -> last_day -> ( -> date_add(now(), interval 1 month) -> ) -> as lastDayOfNextMonth -> ;
The following is the output displaying the first and last day of the next month.
+---------------------+--------------------+ | firstDayOfNextMonth | lastDayOfNextMonth | +---------------------+--------------------+ | 2019-02-01 | 2019-02-28 | +---------------------+--------------------+ 1 row in set (0.00 sec)
Advertisements