
- 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 last days of all the months in MySQL?
To get the last days of all the months, use the LAST_DAY() function from MySQL −
SELECT LAST_DAY(yourColumnName) from yourTableName;
Let us first create a table −
mysql> create table DemoTable ( ShippingDate date ); Query OK, 0 rows affected (0.69 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2019-01-12'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('2019-02-01'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('2019-03-04'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('2019-04-21'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+--------------+ | ShippingDate | +--------------+ | 2019-01-12 | | 2019-02-01 | | 2019-03-04 | | 2019-04-21 | +--------------+ 4 rows in set (0.00 sec)
Following is the query to get the last days of all the months in MySQL −
mysql> select LAST_DAY(ShippingDate) from DemoTable;
Output
+------------------------+ | LAST_DAY(ShippingDate) | +------------------------+ | 2019-01-31 | | 2019-02-28 | | 2019-03-31 | | 2019-04-30 | +------------------------+ 4 rows in set (0.00 sec)
- Related Articles
- How to get the records of the last two days from the current date in MySQL?
- MySQL SELECT last few days?
- Get the sum of last 3 digits from all the values in a column with MySQL
- Get all rows apart from first and last in MySQL
- Get total in the last row of MySQL result?
- Order by last 3 months first, then alphabetically in MySQL?
- How to get days, months and years between two Java LocalDate?
- Get the second last row of a table in MySQL?
- C program to convert days into months and number of days
- Java Program to get date for all the days of the current week
- How to get last day of the current month in MySQL?
- How to get last day of the previous month in MySQL?
- How to get last day of the next month in MySQL?
- Get the first and last date of next month in MySQL?
- Query MySQL table and fetch rows posted before the last 3 days?

Advertisements