
- 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
Convert DateTime Value into String in MySQL?
To convert the DateTime value into string in MySQL, you can use the DATE_FORMAT() function. The syntax is as follows −
select date_format(yourColumnName, ‘%d %m %y’) as anyVariableName from yourTableName;
To understand the above concept, let us create a table. The query to create a table is as follows −
mysql> create table DateAsStringDemo -> ( -> YourDateTime datetime -> ); Query OK, 0 rows affected (0.57 sec)
Inserting the date with the help of curdate() method. The query to insert date is as follows −
mysql> insert into DateAsStringDemo values(curdate()); Query OK, 1 row affected (0.24 sec)
Let us display all records with the help of select statement. The query is as follows −
mysql> select *from DateAsStringDemo;
The following is the output −
+---------------------+ | YourDateTime | +---------------------+ | 2018-11-26 00:00:00 | +---------------------+ 1 row in set (0.00 sec)
The query to convert date to string is as follows −
mysql> select date_format(YourDateTime,'%d %m %y') as YourDateAsString from DateAsStringDemo;
The following is the output −
+------------------+ | YourDateAsString | +------------------+ | 26 11 18 | +------------------+ 1 row in set (0.00 sec)
- Related Questions & Answers
- Python Pandas - Convert string data into datetime type
- How to convert Python DateTime string into integer milliseconds?
- Insert datetime into another datetime field in MySQL?
- How to convert MySQL DATETIME value to JSON format in JavaScript?
- Convert INT to DATETIME in MySQL?
- How to convert string to 24-hour datetime format in MySQL?
- How to convert timestamp to datetime in MySQL?
- Convert datetime to get month name in MySQL?
- Convert Short into String in Java
- Convert string to DateTime and vice-versa in Python
- MySQL query to convert a string into a month (Number)?
- How to convert MySQL datetime to Unix timestamp?
- MySQL Query to convert from datetime to date?
- How to convert DateTime to a number in MySQL?
- Convert from varchar to datetime and compare in MySQL?
Advertisements