Solved

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

Posted on 2013-06-16
3
353 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
Comment Utility
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
Comment Utility
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
Comment Utility
tmp table is a great idea!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

7 Experts available now in Live!

Get 1:1 Help Now