![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 convert yyyymmdd in INT type to date?
For this, you can use the DATE() function. Let us first create a table −
mysql> create table DemoTable ( Number int ); Query OK, 0 rows affected (0.48 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(20190108); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(20161231); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(20170411); Query OK, 1 row affected (0.09 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----------+ | Number | +----------+ | 20190108 | | 20161231 | | 20170411 | +----------+ 3 rows in set (0.00 sec)
Following is the query to convert yyyymmdd in int type to date −
mysql> select date(Number) from DemoTable;
This will produce the following output −
+--------------+ | date(Number) | +--------------+ | 2019-01-08 | | 2016-12-31 | | 2017-04-11 | +--------------+ 3 rows in set (0.00 sec)
Advertisements