Solved

Import excel file into mySQL with correct format

Posted on 2011-09-14
14
1,284 Views
Last Modified: 2012-06-27
Hello!

Was wondering - well hoping one you guys will be able to help me out?!

I'm trying to add data from an excel file to my DB in mySQL (xampp).

I have managed to add data to all of my tables except one. The data is added when I import it, only problem is the one column is date format - but once its in mySQL it is shown as a integer.
e.g. 28/03/2006 in excel and then once imported to mySQL its shown as 38804.00000

I have tried to change the structure of the table  - change the integer field to date format - but that ends up changing all the values under that column to 0000-00-00

Hope one of you guys can help out!
Chelsea
0
Comment
Question by:h3rm1t9536
  • 8
  • 5
14 Comments
 
LVL 9

Expert Comment

by:jeremycrussell
Comment Utility
You will have to set that column as a varchar or text type to be able to import a date formatted like that.
0
 

Author Comment

by:h3rm1t9536
Comment Utility
Image
0
 

Author Comment

by:h3rm1t9536
Comment Utility
If I change the format type to text in excel the values are changed to integers
eg. 28/03/2006 is shown as 38804

I dont mind how the date is displayed as long as it is a date and not a integer...
0
 

Assisted Solution

by:rmnanney
rmnanney earned 250 total points
Comment Utility
1. You can transform the date in excel with this formula =MID(N1,7,4)&"-"&MID(N1,4,2)&"-"&MID(N1,1,2) in a temporary column.

2. Save the file as a CSV, exit Excel.

3. Open the CSV, cut the values from your temporary column and paste them over your dates in column 'N'

4. Save once more and import.
0
 

Author Comment

by:h3rm1t9536
Comment Utility
Hi rmnanney - sounds great but could you please explain a little more what you mean?

Must I copy the formula to each cell in a new column? I have 14000 rows - is it possible to drag and copy (only asking cause I noticed the value changes if I do it that way) or must i do a special paste > value for a whole new column?

Thanks for your help!
0
 

Assisted Solution

by:rmnanney
rmnanney earned 250 total points
Comment Utility
What you want to do is copy that formula (from here) and then click the first cell in your Excel file, let's say column O (really you can choose any column you wish, but it should not contain any of your data)

Next, scroll all the way down to your last row in the file (your last row in column N that has data) hold down the shift key and click the last cell in column O.  This will highlight all the appropriate cells in column O.

Last, you can paste the formula and it should calculate the new dates in column O, appropriate for MySQL import.

This should satisfy step 1 in my earlier comment and you can proceed into step 2.  I strongly suggest you make a backup of your original file just for safety's sake.

I hope this helps,
Ryan
0
 

Author Comment

by:h3rm1t9536
Comment Utility
Hi Ryan

Thanks for explaining... I managed to get to step 3 but this is what the data looked it... not sure if that's what its suppose to look like?
 both columns
Also what type of cvs do I save the file as csv (comma delimited) ?

Also when I try to import the csv file xampp asks a few questions - how do I know which ones to select?
 options
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:h3rm1t9536
Comment Utility
sorry included the wrong image should be this one After Step 3
0
 

Accepted Solution

by:
rmnanney earned 250 total points
Comment Utility
Couple of things to switch up at this point.  

Be sure to save the file as a comma delimited CSV
When trying to import your data in with PHPMyAdmin, switch the "Fields Terminated By" to a comma ',' instead of a semicolon ';'

With regards to your latter screenshot of the excel file, try to format column Q as text.  I have attached a screenshot to illustrate what you want to see when starting step 3.   The format you are after is YYYY-MM-DD for MySQL.

Screenshot of Excel
If you would like to attach the xls file (say with only your dates) I will happily setup the formula and column formatting for you, as an example.  Actually, now that I have typed (thought about it) I have proactively attached a small example for you.  :)

Cheers,
Ryan
Book1.xlsx
0
 

Author Comment

by:h3rm1t9536
Comment Utility
Hi Ryan

Thanks so much for all your help! managed to get all the dates in text format dd-mm-yyyy only issue is when I import the data into MySQL it doesn't format that column as 'DATE' format it views it as VAR CHAR 10.

So the display is perfect with VAR CHAR format only problem is I would like it to be in the correct form 'DATE' When I convert/change the format of OrderDate it is unable to show the correct dates as the picture below shows... MySQL screen shots
The format in excel column 'P' was set to 'Text' before I imported the data to MySQL. I also tried to set the data in excel column 'P' with format 'Date' and then tried to import that to MySQL - but both didn't work...

Thanks again for all your help!!
Chelsea
0
 

Assisted Solution

by:rmnanney
rmnanney earned 250 total points
Comment Utility
Chelsea,

Looks like you're getting close.  Here's what to do next:

You must have your date format YYYY-MM-DD for importation into MySQL, and save that as text in Excel.

Once you import the CSV file into MySQL, the dates will likely be in VARCHAR() format, as you saw.  The only reason your OrderDate did not convert to DATE() in MySQL is because the OrderDate is DD-MM-YYYY.  Just be sure to get the dates as YYYY-MM-DD and do your import and convert to DATE() again.  It should work for you.

Kind regards,
Ryan
0
 

Author Comment

by:h3rm1t9536
Comment Utility
Woohoo its sorted!

Ryan thanks so so much for all your help! Your been a star!
0
 

Expert Comment

by:rmnanney
Comment Utility
Nice!  Glad to see it is working!

Cheers,
Ryan
0
 

Author Closing Comment

by:h3rm1t9536
Comment Utility
Thanks so much!
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

771 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