

- 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
How do I re-format datetime in MySQL?
To re-format datetime in MySQL, you can use DATE_FORMAT(). MySQL gives in the format yyyy-mm-dd.
Let us first create a table −
mysql> create table DemoTable1558 -> ( -> EmployeeJoiningDate datetime -> ); Query OK, 0 rows affected (1.10 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1558 values(CURDATE()); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1558 values(NOW()); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1558 values('2018-01-10'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1558 values('2017-12-31'); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1558;
This will produce the following output −
+---------------------+ | EmployeeJoiningDate | +---------------------+ | 2019-10-13 00:00:00 | | 2019-10-13 17:55:33 | | 2018-01-10 00:00:00 | | 2017-12-31 00:00:00 | +---------------------+ 4 rows in set (0.00 sec)
Following is the query to re-format date time in MySQL −
mysql> select date_format(EmployeeJoiningDate,'%d-%m-%Y') as changeFormat from DemoTable1558;
This will produce the following output −
+--------------+ | changeFormat | +--------------+ | 13-10-2019 | | 13-10-2019 | | 10-01-2018 | | 31-12-2017 | +--------------+ 4 rows in set (0.00 sec)
- Related Questions & Answers
- Add10 minutes to MySQL datetime format?
- Insert current date in datetime format MySQL?
- How do you display JavaScript datetime in 12hour AM/PM format?
- How do I format a number as decimal to store it in MySQL?
- How to convert string to 24-hour datetime format in MySQL?
- How to convert MySQL DATETIME value to JSON format in JavaScript?
- How do I print a Python datetime in the local timezone?
- How to re-arrange data from long format to wide format in R?
- Adding a day to a DATETIME format value in MySQL?
- How do I convert a datetime to a UTC timestamp in Python?
- String format for DateTime in C#
- How do I format the axis number format to thousands with a comma in Matplotlib?
- How do I lag columns in MySQL?
- How to use MySQL FROM_UNIXTIME() function to return datetime value in numeric format?
- What is the correct DateTime format for a MySQL Database?
Advertisements