
- 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
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 Articles
- How to compare Year, Month and Day in a MySQL query and display matching records
- Fetch date records comparing with the current date’s day and month in MySQL
- MySQL query to subtract date records with week day and display the weekday with records
- 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?
- Create date from day, month, year fields in MySQL?
- How to display the day name on the basis of Date of Birth records in MySQL?
- How to get the first day of next month in MySQL?
- Filter the records of current day, month and year in MySQL?
- Finding day of week from date (day, month, year) in JavaScript
- MongoDB query to search date records using only Month and Day
- Format MySQL date and convert to year-month-day
- How can we fetch month and day from a given date in MySQL?
- How to get the first day of the current month in MySQL?

Advertisements