
- 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 to insert mm/dd/yyyy format dates in MySQL?
For this, use STR_TO_DATE(). Following is the syntax −
insert into yourTableName values(STR_TO_DATE(yourDateValue,yourFormatSpecifier));
Let us first create a table −
mysql> create table DemoTable ( ShippingDate date ); Query OK, 0 rows affected (0.81 sec)
Insert some records in the table using insert command : Here, we are inserting formatted dates using date formats like m, d, y, etc −
mysql> insert into DemoTable values(STR_TO_DATE('06-01-2019', '%m-%d-%Y')); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(STR_TO_DATE('01-31-2019', '%m-%d-%Y')); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(STR_TO_DATE('02-01-2018', '%m-%d-%Y')); Query OK, 1 row affected (0.27 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+--------------+ | ShippingDate | +--------------+ | 2019-06-01 | | 2019-01-31 | | 2018-02-01 | +--------------+ 3 rows in set (0.00 sec)
- Related Articles
- MySQL query to convert YYYY-MM-DD to DD Month, YYYY date format
- Convert MySQL date format from yyyy-mm-ddThh:mm:ss.sssZ to yyyy-mm-dd hh:mm:ss ?
- MySQL date format DD/MM/YYYY select query?
- How to parse Date from String in the format: dd/MM/yyyy to dd/MM/yyyy in java?
- MySQL date format to convert dd.mm.yy to YYYY-MM-DD?
- How to format JavaScript date into yyyy-mm-dd format?
- Get date format DD/MM/YYYY with MySQL Select Query?
- How to convert MM/YY to YYYY-MM-DD in MYSQL?
- Java Program to format date in mm-dd-yyyy hh:mm:ss format
- Get today's date in (YYYY-MM-DD) format in MySQL?
- Change date format (in DB or output) to dd/mm/yyyy in PHP MySQL?
- Program to reformat date in YYYY-MM-DD format using Python
- MySQL - Convert YYYY-MM-DD to UNIX timestamp
- Accepting date strings (MM-dd-yyyy format) using Java regex?
- How to format a string to date in as dd-MM-yyyy using java?

Advertisements