The earlier suggestion to use «yyyy-MM-dd HH:mm:ss» is fine, though I believe Excel has much finer time resolution than that. I find this post rather credible (follow the thread and you’ll see lots of arithmetic and experimenting with Excel), and if it’s correct, you’ll have your milliseconds. You can just tack on decimal places at the end, i.e. «yyyy-mm-dd hh:mm:ss.000».
You should be aware that Excel may not necessarily format the data (without human intervention) in such a way that you will see all of that precision. On my computer at work, when I set up a CSV with «yyyy-mm-dd hh:mm:ss.000» data (by hand using Notepad), I get «mm:ss.0» in the cell and «m/d/yyyy hh:mm:ss AM/PM» in the formula bar.
For maximum information[1] conveyed in the cells without human intervention, you may want to split up your timestamp into two or three pieces: a date portion, a time portion to the second, and optionally a fractional seconds portion. It looks to me like Excel wants to give you at most three visible «levels» (where fractions of a second are their own level) in any given cell, and you want seven: years, months, days, hours, minutes, seconds, and fractions of a second.
Or, if you don’t need the timestamp to be human-readable but you want it to be as accurate as possible, you might prefer just to store it as a big number (internally, Excel is just using the number of days, including fractional days, since an «epoch» date).
[1]That is, information stored numerically and suitable for use in calculations. If you simply want to visually see as much information as possible, or only need it for sorting/filtering (no date or time arithmetic), you could make up some format which Excel will definitely parse as a string, and thus leave alone; e.g. «yyyymmdd.hhmmss.000».
Summary of this page: Excel will respect your date formatting as long as you save the file as an XLSX (Excel file). Make your changes, format all date columns as shown below, then save the file as an Excel spreadsheet. Use THE EXCEL-TYPE file to make future changes or updates. When you’re done and ready to import, Save As and select CSV (comma-separated-values) as the file type. The CSV file will have the proper date format. Just don’t open the CSV file in Excel and expect the dates to be formatted correctly. Always use the *.xlsx version to make updates, in order to retain required date formatting.
Some of the CSV imports contain date fields, in particular the capture/schedules import. The required format for date fields is yyyy-mm-dd. This is an international standard date format, designed to reduce confusion.
Many users work with CSV files using a spreadsheet program like Microsoft® Excel. The PROBLEM is that Excel will automatically reformat what it recognizes as a date into the default date format configured for your system. Which may not be yyyy-mm-dd.
What this means is that even if your CSV file is correct (open it in Notepad or Wordpad to see the raw data), the reformatted date field will be wrong in Excel. And after you make changes and save the CSV file, the wrong date format showing in Excel will be applied to the fields.
This is bad, because now your CSV import won’t work.
DON’T PANIC! Use the instructions below to change the date format in your spreadsheet. Basic steps: select the date column, right-click and select Format Cells, then select Custom and enter yyyy-mm-dd in the text field.
To reformat the date fields in an Excel spreadsheet
- Open the .csv file in Excel.
-
RIGHT-CLICK the tile above the Start Date column header. (Press control+click if using a Mac)
This selects the entire column and opens a shortcut menu as shown below.
- Select Format Cells from the shortcut menu.
- If necessary, select the Number tab (it should appear by default).
- Select Custom from the number Category list.
- In the Type field, replace the text that appears with yyyy-mm-dd.
- Click OK.
- Repeat these steps for the End Date column.
- When finished, Save the file as an Excel file (.xls or .xlsx), then Save As a .csv file.
The saved CSV file will have the proper date formatting for importing to Echo360; the Excel file will retain the format changes and can be used again later to generate a new schedule import file.
If you want to be CERTAIN the CSV file is correct, open the file in Notepad or Wordpad and look for the date; if you changed the format in Excel to yyyy-mm-dd and saved as CSV, the date will appear in this format in the raw csv file. Don’t use Excel to check it; Excel will convert the dates back to the system default format.
Identifying the columns correctly
The first step in importing a CSV file into Easy Excel Analysis is to ensure that each column is correctly identified. In this example, we will work with the sample CSV file:
When we first open this file in Easy Excel Analysis and click on the Preview button, an error is raised regarding the number of columns.
Our CSV file encloses text in quotes, so we’ll need to select the Field values are quoted using “ option (since we’re using double quotes as the quote character), and click Preview again:
All the columns seem to be in order, so we can proceed.
Adjusting the date format
On the next page, Easy Excel Analysis has set up the date and time formats based on our computer’s settings.
The date format is different from that in our CSV file:
If we continue to the next step, our OrderDate column will be identified as a Text field, because the date format in the CSV file does not match our settings.
Thus, we’ll need to change the date format settings accordingly. Go back to the previous step, and select the correct date format from the list of pre-defined formats, or enter the format manually. Note that d represents the date, m for month, and yyyy for the year.
Once we have set up the date format to correctly match that in our CSV file, Easy Excel Analysis will set up the OrderDate column as a Date and time column.
If your date columns contain month names e.g.
then just enter a blank value as the date format. Easy Excel Analysis will then try to parse the value as best as it can.
Adjusting the time format
Adjusting the time format is similar to the steps described above for date formats. You can manually enter a format value if none of the listed formats match.
Frustrated with incorrect dates while opening csv file in excel? This is very common. But you can also overcome easily in different ways
•
Aug. 17, 2019
You may jump to :
- Why excel do not recognize all the dates in CSV:
- How do I understand if excel could open my csv?
- Understand Date Locale:
- Solution 1: Change the Locale or Region and Language
- Solution 2 : Use Text Import Wizard
- Solution 3: Use latest version of Office
Very often people face issues when they are opening csv file and that have dates. When date is exported or saved most of the program or applications uses Month-Day-Year. If your locale or Region & Language (Date format : position of day and month) is not the same, then excel do not understand all the dates and create inconsistencies. We will see how to overcome that situation in different ways. But before that let us see why we are facing this issue. This can help you to think some other way to solve your situation
Why excel do not recognize all the dates in CSV:
Excel internally stores date information as a number and while displaying on screen, it shows the date in a format that is setup on your computer as Region and Language settings. If you put 0 in a cell and change the format of the cell as date, you will see it as 1st January, 1990. On the other hand, in CSV or a TEXT file all data are texts only. Excel needs to convert it to date, otherwise, calculations like adding dates, or comparing it with other dates, filtering for year etc is not possible. To interpret or understand the data in CSV, excel uses Region and Language setting. While using that, excel determines which part of date text from csv is the day and which part is the month. Suppose, it has determined that the first part is the month. Now, during converting that to date, if the month section is more than 12, it cannot consider the entire data as date. So, whenever it is not able to convert that to date, it will keep that as Text and rest of that will be converted to DATE data. If there is a single case of Excel not able to convert that as date data, I would assume that the csv have date from different Region and Language and all the date conversion is incorrect. You can see below the Region and Language settings. depending on your windows version the look may be different
How do I understand if excel could open my csv?
Usually, Texts are left aligned in excel. Numbers are right aligned. If you increase the column width, you can clearly see some dates are left aligned and some of them are right aligned. Left aligned are the ones that have not been considered as Date data. But Obviously, in this case the date that has been considered date are wrong. As you can see, if the dates format in the source CSV was same as the Region and Language (Locale) settings, then all of the date should have been in the date format. This is pictorially explained in the picture below
How Do I solve the puzzle?
There are different ways you can address this issue. I would cover three methods in this article
Understand Date Locale:
Get the information or determine yourself if the data has UK Date format (DD/MM/YY) or US Date format (MM/DD/YY). If you are unsure about it, look at the CSV file for a date related field and determine which section represents Days. It should have number greater than 12. You would be able to eliminate the year field quickly looking at the data as same Year value would be there for large number of data. If the date is the First part then it is UK format otherwise it should be US. There is one more well known date format and that is ISO. It starts with Year followed by Month and subsequently by Date
Solution 1: Change the Locale or Region and Language
Easiest solution is to change the Locale or Region and Language setting of your computer to that of the Source Data.
On your windows Search type in Region and Language. You will see it under control Panel. Open it and change the date format to match the source file. open the csv file and verify that the data has been correctly interpreted by Excel. You may save the data as excel (use Save as). After saving the data, if need be, you can change the Region and Language setting back to the original.
Solution 2 : Use Text Import Wizard
Open the file as plain text file and define date Columns.
- Rename the file to change or add extension as txt. For example test.csv file is changed to test.csv.txt
- Open Excel .
- Use Menu File -> Open and then browse to the file.
- This will invoke Excel’s Text Import Wizard. Follow the next instructions and illustrations
- First Select Delimited and click Next
6. Select the delimiter as per your file. in this example the delimiter used is comma(,) . Now Excel understand the data fields. you can see data are seperated from each other by a vertical line. Please click Next
7. Now, at step 3 of the Text Import wizard, you have to make Excel understand the type of data that each column or field contains. First Select the column, where you have the date data. Next, select the Date option. Then from the dropdown select the date field type option. If your source data starts with Month followed by Day and then Year, then select MDY .. and so on
There is a limitation — if a single row contains date and Time both, excel fails to interpret that correctly. So, we need to force excel to consider that data as test and not to do any operation on it.
8. Select the field that has both Data and Time together. Then select Data type as Test and click on finish
You see the final result here
Solution 3: Use latest version of Office
Latest version of excel have overcome these issues. You have to use Get Data options under Data to import the data. This wizard understands different date data format including data which is a combination of Date and Time. This do not give you an option to choose different Date formats but it understands it correctly. I have checked different complex options and it worked in all the combinations. There is one catch. The imported data are stored in a table in Excel. You can use Convert to Range from Table contextual menu
Hope that this solves your CSV import issue in excel
First, the formatting thing. Excel looks at the first 8 records (yes, just 8, even for a 500,000 row import) to decide the formatting to apply. The trivial half of that is that you are almost certainly getting 12:27:23 displayed as 27:23.0 because the first records in the CSV have times pretty close to midnight, so, say 00:01:25.043. Excel sees eight records like that and figures you need to display minutes, seconds, and the single decimal. No matter you have 400,000 records with hours too vs. 28 or 435 or whatever with «00» for the hours.
This points to the bigger issue: why is the date not included in that formatting? If you look at those first records, you might find the dates are not present, or in some way, the value is 0. So Excel sees date and formats only for time, and cripples that too.
You could do a lot of things. Power Query is your salvation here and I will expand a small amount on that shortly. But in the tradition of shows on Atlantis-finding, Let’s spend 58 minutes pooh-pooh-ing the other solutions, then a second or two on PQ.
First, VBA. No pooh-pooh-ing this actually. Just open the file, and run a macro that adjusts the formatting for columns you need formatted. Write Once, Use Many Times. WOUMT. Nope, won’t catch on. One bit of effort, use forever. Put it in some drone file you open before opening the tons of files and have it operate on the opened CSV.
Second, create a template file with the formatting you need. Open the CSV and immediately copy and paste the data into the template file. All done. Save it with the right name and move on to the next one.
Third, format by hand. I bet there aren’t a lot of columns here, so it’s not unbearable. Formatting by hand could be done via a template file that you copy the first row from to the clipboard, then Paste | Special | Formatting (or Alt-E, S, T
) to all the rows of the newly opened CSV. So, not actually hard or time consuming.
Well, that’s enough. Notice a thread there as you object to each. You might think «don’t like macros» or «don’t know VBA» or «I just ain’t doin’ nothin’ by hand, dude» or «open a template, copy and paste or paste once to get the formatting, ugh, that’s so much work» but I wager you are coming back to the «tons of files» thing.
Tons of files, tons of work, only so many years in your life. This is what VBA was created for. VBA truly is a wonder for what you describe. Geez, even, horrors, paying someone a few hundred dollars to write the macro you need for opening file after file after file and formatting, then saving with appropriate names, placing in your directory structure where needed, even emailing them or what-have-you… all this for a few hundred dollars. An organization with tons of files to process has the cash for something like that and bosses that respect someone who sees the best solution isn’t him and HANDLES the situation cost-effectively and time-effectively.
But truthfully, PQ can do VBA one better in many ways. It can be set up for the import, and massaging of the data formatting and such, without too much trouble. Then it keeps all of that in itself (the good old «Data Model») and can do it to a million files without complaint. It can handle as many rows as your memory can, not just a million like Excel. And its results can be accessed via Power Pivot (which comes with Excel) and Excel and, well, a lot of other programs. One weakness here is the filename it is looking at, but its SQL (it does all this via SQL, «under the hood» if you like) can be edited by anyone who knows SQL. Need an outsider? Back to that few hundred dollars thing, but an SQL gal might charge somewhat more than the VBA guy. Anyway, It ought to be able to be modified to handle a directory full of files if you like.
And it has one monstrous advantage over VBA, if needed: it can combine those files naturally and with ease. You thought you were going to use Excel itself to analyze data but had 15 million rows? Had to have it broken into a ton of files to import into spreadsheets, then to cobble together formulas to read it all and bring it into focus? Didn’t ask for that, but the provider, who wrote their export routines 25 years ago simply provided it that way because any other way takes work while this is just a mouseclick? PQ can put it all back together, seamlessly, like it was never broken up. It was similar material from 25 different sources and your project actually is to put it together? Same thing to PQ, same ease of doing.
So… if YOUR task is only to import and save it as Excel files with appropriate formatting for use by someone else, VBA. If you need to use it yourself, or there is a next step of putting it together for a bigger analysis, wow the boss who thought he had to budget for two projects by using PQ to do it all in one fell swoop.
A teensy detail that I skipped earlier since you made it clear you do not want to put a lot of effort into each import: if you open each file in an editor and move a dozen or two rows with more «fully detailed» data to the top rows of the file, the more fully detailed rows will be what Excel looks to when gauging how to format the columns. If it had seen the first row in your sample material first, you’d’ve had a full date and time display like: 2020-07-30 12:27:23.0
and none of this would have ever vexed you.
But… that’s maybe more work than formatting things so I didn’t figure you would be interested.
It is also possible to force Excel to look at as many rows as you’d care to have looked at instead of 8. However, bear in mind three things:
- You would have to research that because I don’t remember how. Been a long time. I mentioned it in a different question and the «usual (knowledgeable) suspects» were there but no one filled the poster in on it so it seems it’s not casually found.
- Your data might routinely have a LOT of unhelpful rows coming first. Thank the fellow who exported it sorted like that. But if you are importing half a million rows the first 10-20,000 might be betwwen midnight and 1:00 am and to reach rows with full detail might go a long way past that. That could mean a LONG lag in the import, could even mean Excel choking and failing.
- Bearing in mind that lag, it might be easier to open the files in an editor and either move fully representative rows to the start, or actually simply copy a set of, say, 10-20 rows of fully representative data to a file, then copy those rows to EVERY file’s beginning, and delete those rows immediately upon import. The quickness of the import process vs. bogging down considering 10-20,000 rows or more befor even starting to import should easily outweigh the work just described.