
- 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
MySQL query to extract only the day instead of entire date
To extract only the day instead of the entire date, you need to use DAYOFMONTH() function from MySQL.
Let us first create a table −
mysql> create table DemoTable747 (DueDate datetime); Query OK, 0 rows affected (0.53 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable747 values('2019-01-31') ; Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable747 values('2018-12-01'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable747 values('2017-09-14'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable747 values('2016-07-21'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable747;
This will produce the following output -
+---------------------+ | DueDate | +---------------------+ | 2019-01-31 00:00:00 | | 2018-12-01 00:00:00 | | 2017-09-14 00:00:00 | | 2016-07-21 00:00:00 | +---------------------+ 4 rows in set (0.00 sec)
Following is the query to extract only the day instead of entire date −
mysql> select dayofmonth(DueDate) from DemoTable747;
This will produce the following output -
+---------------------+ | dayofmonth(DueDate) | +---------------------+ | 31 | | 1 | | 14 | | 21 | +---------------------+ 4 rows in set (0.00 sec)
- Related Articles
- How to update only day portion of MySQL Date?
- MongoDB query to search date records using only Month and Day
- MySQL query to update only month in date?
- MySQL query to return the entire date and time based on a string and format
- MySQL query to get current datetime and only current date
- Compare only day and month with date field in MySQL?
- MySQL query with two boolean conditions to extract date based on hour?
- Format date to display month names with the entire date in MySQL?
- A single MySQL query to update only specific records in a range without updating the entire column
- MySQL query to subtract date records with week day and display the weekday with records
- What would be output if we will try to extract time values by providing the date values only to MySQL EXTRACT() function?
- How to extract from datetime column in MySQL by comparing only date and ignoring whitespace?
- MongoDB query to search for Month and Day only?
- How to extract only the month and day from a datetime object in Python?
- MySQL extract year from date format?

Advertisements