![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 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)
Advertisements