
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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)
- Related Articles
- How to get last day of the next month in MySQL?
- How to get the first day of next month in MySQL?
- How to get first and last date of the current month with JavaScript?
- How to display first day and last day of the month from date records in MySQL?
- How to get the same or first day of next month on a given date in Excel?
- How to get last day of the current month in MySQL?
- How to get last day of the previous month in MySQL?
- Get last second of a date in MySQL?
- How to get the first day of the current month in MySQL?
- How to get the first day of the previous month in MySQL?
- How to get the first and last record of the table in MySQL?
- Get the last day of month in Java
- How to compare the first date and the last date from a MySQL column with date records?
- Get all rows apart from first and last in MySQL
- How to get first day of every corresponding month in MySQL?

Advertisements