
- 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
Format date while inserting records in MySQL
To format date while inserting records, use DATE_FORMAT() in the MySQL INSERT statement. Let us first create a table −
mysql> create table DemoTable2012 -> ( -> ShippingDate varchar(20) -> ); Query OK, 0 rows affected (0.48 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable2012 values(date_format(curdate(),'%d.%m.%Y')); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable2012 values(date_format(now(),'%d.%m.%Y')); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable2012 values(date_format('2014-01-21','%d.%m.%Y')); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable2012;
This will produce the following output −
+--------------+ | ShippingDate | +--------------+ | 21.12.2019 | | 21.12.2019 | | 21.01.2014 | +--------------+ 3 rows in set (0.00 sec)
- Related Articles
- Can we use INTERVAL keyword while inserting date records in a MySQL table?
- Display an error while inserting duplicate records in a MySQL table
- Escaping quotes while inserting records in MongoDB?
- Update the date and time values while inserting them in MySQL
- UNIX_TIMESTAMP with date in MySQL query to fetch records after a specific date in different format?
- Inserting records into a MySQL table using PreparedStatement in Java?
- In MySQL, how can I insert date and time automatically while inserting NULL values to the other columns?
- 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?
- MongoDB query to fetch date records (ISODate format) in a range
- Insert current date in datetime format MySQL?
- Set a specific Date Format in MySQL?
- How to convert positive value to negative while inserting in MySQL?
- Can we skip a column name while inserting values in MySQL?

Advertisements