MySQL Forums
Forum List  »  Newbie

Re: Import From Text File (Different Date Format)
Posted by: Mike Miller
Date: October 17, 2007 09:40AM

Roy: I, too, was looking for how to do this and couldn't find anything. I got about 23,000 records with the date format of: mm/dd/yyyy 00:00:00. The time protion of the record were all 0's so I wanted to ignore them. So here was my process.
1. Changed the field definition for the date field to varchar
2. Imported normally
3. ran this query (after I backed up! :-)
update MYTABLENAME set MYDATEFIELD=concat(
substring(
substring_index(MYDATEFIELD,"/",-1),1,4
),"-",
substring_index(MYDATEFIELD,"/",1),"-",
substring_index(
substring_index(MYDATEFIELD,"/",2),"/",-1
)
)
4. Then I changed the field definition back to datetime
You may want to look at that substring_index command...pretty handy.

Hope that helps!

Options: ReplyQuote


Subject
Written By
Posted
Re: Import From Text File (Different Date Format)
October 17, 2007 09:40AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.