Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving to CSV in Excel loses regional date format

I have a .xls I need to convert to .csv

The file contains some date columns. The format on the date is "*14/03/2001" which, according to Excel means the date responds to regional date and time settings specified for the OS.

Opening in Excel you see:

20/01/2013
01/05/2013

Save as... CSV

Open in notepad:

01/20/2013
05/01/2013

I have temporarily fixed by setting date formats to "14/03/2001" (no *) but even some other custom formats with no *, like "d/mm/yyyy h:mm" get mangled when saved to CSV.

like image 900
upshake Avatar asked Feb 07 '13 23:02

upshake


People also ask

Why does my exported CSV data get converted to weird format?

Instead, this is due to the way Excel and other spreadsheet programs open a CSV file and display the data therein. Basically, spreadsheet programs are designed to be used for calculation purposes, so they tend to apply mathematical formats to numbers when the CSV file is opened directly into the program.

How to save date format from Excel to CSV file?

You can save your desired date format from Excel to .csv by following this procedure, hopefully an excel guru can refine further and reduce the number of steps: Create a new column DATE_TMP and set it equal to the =TEXT( oldcolumn, "date-format-arg" ) formula.

Why can’t I open a CSV file with dates?

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.

How do I convert a CSV file to excel?

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 ).

What is the date format in the XLS file?

The xls contains dates formatted as dd/mm/yyyy. However, when the 'save as' code is executed the format is lost. The csv file contains mm/dd/yyyy.


1 Answers

Although keeping this in mind http://xkcd.com/1179/

In the end I decided to use the format YYYYMMDD in all CSV files, which doesn't convert to date in Excel, but can be read by all our applications correctly.

like image 159
upshake Avatar answered Oct 02 '22 11:10

upshake