
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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 Articles
- Insert current date in datetime format MySQL?
- How to Convert Text Datetime Format to Real Datetime Format in Excel?
- How do you display JavaScript datetime in 12hour AM/PM format?
- 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 format a number as decimal to store it in MySQL?
- Add10 minutes to MySQL datetime format?\n\n
- Adding a day to a DATETIME format value in MySQL?
- How to re-arrange data from long format to wide format in R?
- How to use MySQL FROM_UNIXTIME() function to return datetime value in numeric format?
- How do I print a Python datetime in the local timezone?
- What is the correct DateTime format for a MySQL Database?
- How to Convert yyyymmddhhmmss Date Format to Normal Datetime in Excel?Datetime in Excel?
- How do I convert a datetime to a UTC timestamp in Python?
- String format for DateTime in C#

Advertisements