
- 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 convert US date format to MySQL format in INSERT query?
You can use STR_TO_DATE() to convert US date format to MySQL format in INSERT. Let us first create a table −
mysql>create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ShippingDatetime varchar(200) ); Query OK, 0 rows affected (1.04 sec)
Insert some records in the table using insert command. Here, we are using INSERT to convert US date format −
mysql>insert into DemoTable(ShippingDatetime) values(STR_TO_DATE('01-31-2012 01:23','%m-%d-%Y %H:%i')); Query OK, 1 row affected (0.14 sec) mysql>insert into DemoTable(ShippingDatetime) values(STR_TO_DATE('12-01-2018 04:56','%m-%d-%Y %H:%i')); Query OK, 1 row affected (0.19 sec) mysql>insert into DemoTable(ShippingDatetime) values(STR_TO_DATE('04-17-2019 10:10','%m-%d-%Y %H:%i')); Query OK, 1 row affected (0.17 sec)
Following is the query to display all records from the table using select statement −
mysql>select *from DemoTable;
This will produce the following output −
+----+---------------------+ | Id | ShippingDatetime | +----+---------------------+ | 1 | 2012-01-31 01:23:00 | | 2 | 2018-12-01 04:56:00 | | 3 | 2019-04-17 10:10:00 | +----+---------------------+ 3 rows in set (0.00 sec)
- Related Articles
- Convert MySQL Unix-Timestamp format to date format?
- How to convert Python date format to 10-digit date format for mysql?
- How to convert a date format in MySQL?
- Insert current date in datetime format MySQL?
- Convert VARCHAR data to MySQL date format?
- MySQL query to convert YYYY-MM-DD to DD Month, YYYY date format
- MySQL query to convert height format to centimeters?
- How to correctly convert a date format into a MySQL date?
- Convert VARCHAR Date to a different format in MySQL?
- Format MySQL date and convert to year-month-day
- How to convert Python date in JSON format?
- MySQL date format to convert dd.mm.yy to YYYY-MM-DD?
- How to convert milliseconds to date format in Android?
- MySQL date format DD/MM/YYYY select query?
- How to update the date format in MySQL?

Advertisements