- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the easiest way to store date in MySQL database?
To store date in MySQL, use the STR_TO_DATE() method −
insert into yourTableName values(STR_TO_DATE('yourDate', '%d/%m/%Y'));
Let us first create a table −
mysql> create table DemoTable ( AdmissionDate date ); Query OK, 0 rows affected (0.62 sec)
Insert records in the table using insert command −
mysql> insert into DemoTable values(STR_TO_DATE('10/01/2013', '%d/%m/%Y')); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values(STR_TO_DATE('31/01/2015', '%d/%m/%Y')); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(STR_TO_DATE('23/04/2019', '%d/%m/%Y')); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(STR_TO_DATE('01/03/2019', '%d/%m/%Y')); Query OK, 1 row affected (0.48 sec)
Display records from the table using select command −
mysql> select *from DemoTable;
This will produce the following output −
+---------------+ | AdmissionDate | +---------------+ | 2013-01-10 | | 2015-01-31 | | 2019-04-23 | | 2019-03-01 | +---------------+ 4 rows in set (0.00 sec)
- Related Articles
- The easiest way to insert date records in MySQL?
- What is the easiest way to reverse a String in Java?
- What is the easiest way to lose weight without exercise?
- Best way to store date/time in MongoDB?
- What is the easiest way to convert int to string in C++
- How to store and retrieve a date into MySQL database using Python?
- What is the easiest way to transfer files from phone to PC?
- Easiest way to get number of rows in a MySQL table?
- What is the easiest way to convert a List to a Set in Java?
- Best way to store weekly event in MySQL?
- The easiest way to concatenate two arrays in PHP?
- What is the easiest way to initialize a std::vector with hardcoded elements in C++?
- Easiest way to sort an array in MongoDB
- Easiest way to copy values of one column to a new table in MySQL?
- How to store the PayPal decimal amount in the MySQL database?

Advertisements