
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Strip Time Component from Datetime in MySQL
You can strip time component from datetime with the help of DATE() function. The syntax is as follows −
SELECT DATE(yourColumnName) from yourTableName;
To understand the above concept, let us first create a table −
mysql> create table StripComponentDatetimeDemo -> ( -> YourDateTime datetime -> ); Query OK, 0 rows affected (0.60 sec)
Let us now insert some records in the table. The query is as follows −
mysql> insert into StripComponentDatetimeDemo values(date_add(now(),interval 1 day)); Query OK, 1 row affected (0.13 sec)
Display records with the help of select statement. The query is as follows displaying datetime −
mysql> select *from StripComponentDatetimeDemo;
The following is the output −
+---------------------+ | YourDateTime | +---------------------+ | 2018-11-25 20:15:07 | +---------------------+ 1 row in set (0.00 sec)
The following is the query that strips time component −
mysql> SELECT DATE(YourDateTime) from StripComponentDatetimeDemo;
The following is the output −
+--------------------+ | DATE(YourDateTime) | +--------------------+ | 2018-11-25 | +--------------------+ 1 row in set (0.00 sec)
Advertisements