I have several datetime fields in SQL Server that get outputted into CSV files, either as .txt or .csv. When automatically opening the .csv file in Excel 2010, it formats the datetime as mm:ss.0 and drops the date portion completely.
I have read this: Opening a CSV file in excel changes my formats and this: Date format that is guaranteed to be recognized by Excel
Here is a snippet of the raw text stored in the CSV file (.txt). Note the date portion is ISO format. The time portion does have milliseconds.
"EVENTSTARTDATE","EVENTTITLE","PURCHASEDATE"
"2013-04-17 00:00:00.0","Test Event","2013-04-17 15:06:27.56"
Here is the formatting in Excel:
EVENTSTARTDATE EVENTTITLE PURCHASEDATE
00:00.0 Test Event 06:27.6
Clicking on the fields show these values:
EVENTSTARTDATE PURCHASEDATE
4/17/2013 12:00:00 AM 4/17/2013 3:06:28 PM
When I go to "Format Cells..." and look at the field format, it is "Custom" and "mm:ss.0". I can reformat it to a Date format and it works fine, so obviously the data itself is correct. Why is Excel formatting only the time portion, and why dropping the hours? If the field type is "General", shouldn't Excel be able to parse the datetime data?
Other possibly relevant info: I am using ColdFusion 9 and have code that uses the CreateODBCDateTime() function.
<cfif isDate(raw)>
<cfset raw = CreateODBCDateTime(raw)>
</cfif>