

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
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 Questions & Answers
- How to get the records of the last two days from the current date in MySQL?
- MySQL SELECT last few days?
- C program to convert days into months and number of days
- Get total in the last row of MySQL result?
- Get the sum of last 3 digits from all the values in a column with MySQL
- Java Program to get date for all the days of the current week
- How to get days, months and years between two Java LocalDate?
- Order by last 3 months first, then alphabetically in MySQL?
- Get the second last row of a table in MySQL?
- Query MySQL table and fetch rows posted before the last 3 days?
- Get the date/time of the last change to a MySQL database?
- Get the first and last date of next month in MySQL?
- 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?
Advertisements