
- 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
Change the curdate() (current date) format in MySQL
The current date format is ‘YYYY-mm-dd’. To change current date format, you can use date_format().
Let us first display the current date −
mysql> select curdate();
This will produce the following output −
+------------+ | curdate() | +------------+ | 2019-08-08 | +------------+ 1 row in set (0.00 sec)
Following is the query to change curdate() (current date) format −
mysql> select date_format(curdate(), '%m/%d/%Y');
This will produce the following output −
+------------------------------------+ | date_format(curdate(), '%m/%d/%Y') | +------------------------------------+ | 08/08/2019 | +------------------------------------+ 1 row in set (0.00 sec)
Let us first create a table −
mysql> create table DemoTable ( ArrivalDate date ); Query OK, 0 rows affected (0.50 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2019-01-10'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('2016-12-18'); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------------+ | ArrivalDate | +-------------+ | 2019-01-10 | | 2016-12-18 | +-------------+ 2 rows in set (0.00 sec)
Following is the query to change date format −
mysql> select date_format(ArrivalDate, '%m/%d/%Y') from DemoTable;
This will produce the following output −
+--------------------------------------+ | date_format(ArrivalDate, '%m/%d/%Y') | +--------------------------------------+ | 01/10/2019 | | 12/18/2016 | +--------------------------------------+ 2 rows in set (0.00 sec)
- Related Articles
- Insert current date in datetime format MySQL?
- Best way to change the date format in MySQL SELECT?
- How to change date format with DATE_FORMAT() in MySQL?
- Change date format in MongoDB
- Change date format in MySQL database table to d/m/y
- PHP program to change the date format
- PHP program to change date format
- Change date format (in DB or output) to dd/mm/yyyy in PHP MySQL?
- How to change date time format in HTML5?
- How to change American date format in Excel?
- How to update the date format in MySQL?
- MySQL ORDER BY Date field not in date format?
- Extract Numeric Date Value from Date Format in MySQL?
- Convert MySQL Unix-Timestamp format to date format?
- Select dates between current date and 3 months from the current date in MySQL?

Advertisements