?
Solved

How can i transform '12 June 2013' as a DATE TIME

Posted on 2013-06-16
3
Medium Priority
?
359 Views
Last Modified: 2013-06-16
Hiya All

I have a csv file that i will be importing into a MYSQL table once a day and one of the fields is a date filed but I recive it from my source in a "12 June 2013" format.

So what are my options, for importing this CSV via PHPmyAdmin and convert this to a proper useable DATETIME format?
0
Comment
Question by:willa666
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 23

Accepted Solution

by:
nemws1 earned 2000 total points
ID: 39251651
Import your data into a table, making your date field a VARCHAR(30).  Let's say you named it "import_date".

After importing:

ALTER TABLE your_table ADD fixed_date DATETIME;

UPDATE your_table
SET fixed_date = STR_TO_DATE(import_date, "%d %M %Y")
;

ALTER TABLE your_table DROP import_date;

Open in new window


Obviously, the STR_TO_DATE() is the fun part of all this.
0
 
LVL 1

Author Comment

by:willa666
ID: 39251696
Hiya nemws1

That worked great!

I am guessing that i should probably import this as a tmp table and then move this data into to the other data table once the transformation has been completed.

FYI i already added this to the end :)
ALTER TABLE orders_tbl change fixed_date sale_date datetime;

Ww
0
 
LVL 23

Expert Comment

by:nemws1
ID: 39251711
tmp table is a great idea!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question