
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
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)
Advertisements