Solved

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

Posted on 2013-06-16
3
354 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
  • 2
3 Comments
 
LVL 23

Accepted Solution

by:
nemws1 earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now