
- 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
How to display first day and last day of the month from date records in MySQL?
Let us first create a table −
mysql> create table DemoTable -> ( -> DueDate date -> ); Query OK, 0 rows affected (0.73 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2019-01-11'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values('2019-04-19'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------------+ | DueDate | +------------+ | 2019-01-11 | | 2019-04-19 | +------------+ 2 rows in set (0.00 sec)
Following is the query to display first day and last day of month −
mysql> select date_format(DueDate,'%Y-%m-01') as FirstDayOfMonth,last_day(DueDate) as LastDayOfMonth from DemoTable;
This will produce the following output −
+-----------------+----------------+ | FirstDayOfMonth | LastDayOfMonth | +-----------------+----------------+ | 2019-01-01 | 2019-01-31 | | 2019-04-01 | 2019-04-30 | +-----------------+----------------+ 2 rows in set (0.00 sec)
- Related Questions & Answers
- Finding day of week from date (day, month, year) in JavaScript
- 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?
- Filter the records of current day, month and year in MySQL?
- Fetch date records comparing with the current date’s day and month in MySQL
- Create date from day, month, year fields in MySQL?
- How to get the first day of next month in MySQL?
- How to compare Year, Month and Day in a MySQL query and display matching records
- Format MySQL date and convert to year-month-day
- MongoDB query to search date records using only Month and Day
- MySQL query to subtract date records with week day and display the weekday with records
- How to get the first day of the current month in MySQL?
- How to get the first day of the previous month in MySQL?
- Get the last day of month in Java
Advertisements