

- 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 only the date from datetime in MySQL?
To get only the date from DateTime, use the date format specifiers −
%d for day %m for month %Y for year
Let us first create a table −
mysql> create table DemoTable ( AdmissionDate datetime ); Query OK, 0 rows affected (0.52 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2019-07-21 12:34:56'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('2016-08-18 10:00:02'); Query OK, 1 row affected (0.51 sec) mysql> insert into DemoTable values('2018-01-03 11:02:20'); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+---------------------+ | AdmissionDate | +---------------------+ | 2019-07-21 12:34:56 | | 2016-08-18 10:00:02 | | 2018-01-03 11:02:20 | +---------------------+ 3 rows in set (0.00 sec)
Here is the query to get only the date −
mysql> select date_format(AdmissionDate,'%d.%m.%Y') AS Date from DemoTable;
This will produce the following output −
+------------+ | Date | +------------+ | 21.07.2019 | | 18.08.2016 | | 03.01.2018 | +------------+ 3 rows in set (0.00 sec)
- Related Questions & Answers
- MySQL query to get only the minutes from datetime?
- How to select only MySQL date from datetime column?
- MySQL query to get current datetime and only current date
- How to get only Date portion from DateTime object in C#?
- Get only the date in timestamp in MySQL?
- Extracting only date from datetime field in MySQL and assigning it to PHP variable?
- Create DATETIME from DATE and TIME in MySQL?
- How to extract from datetime column in MySQL by comparing only date and ignoring whitespace?
- MySQL Query to convert from datetime to date?
- How to compare DateTime Column with only Date not time in MySQL?
- Compare DATE string with string from MySQL DATETIME field?
- Display only date from timestamp value in MySQL
- How to part DATE and TIME from DATETIME in MySQL?
- Add DATE and TIME fields to get DATETIME field in MySQL?
- Get the sum only from specific cells in MySQL?
Advertisements