ms access - CSV file to Excel 2010 formats datetime fields to time -
i have several datetime fields in sql server outputted csv files, either .txt or .csv. when automatically opening .csv file in excel 2010, formats datetime mm:ss.0 , drops date portion completely.
i have read this: opening csv file in excel changes formats , this: date format guaranteed recognized excel
here snippet of raw text stored in csv file (.txt). note date portion iso format. time portion have milliseconds.
"eventstartdate","eventtitle","purchasedate" "2013-04-17 00:00:00.0","test event","2013-04-17 15:06:27.56"
here formatting in excel:
eventstartdate eventtitle purchasedate 00:00.0 test event 06:27.6
clicking on fields show these values:
eventstartdate purchasedate 4/17/2013 12:00:00 4/17/2013 3:06:28 pm
when go "format cells..." , @ field format, "custom" , "mm:ss.0". can reformat date format , works fine, data correct. why excel formatting time portion, , why dropping hours? if field type "general", shouldn't excel able parse datetime data?
other possibly relevant info: using coldfusion 9 , have code uses createodbcdatetime() function.
<cfif isdate(raw)> <cfset raw = createodbcdatetime(raw)> </cfif>
solved issue. there function call buried in code function:
<cffunction name="querytocsv" access="public" returntype="string" output="false" hint="converts query comma separated value string."> <cfargument name="query" type="query" required="true" hint="the query being converted csv"> <cfargument name="headers" type="string" required="false" default="#arguments.query.columnlist#" hint="the list of field headings used when creating csv value"> <cfargument name="fields" type="string" required="false" default="#arguments.query.columnlist#" hint="the list of query fields used when creating csv value"> <cfargument name="lstdatetimefields" type="string" required="false" default="" hint="the list of fields should output in date/time format"> <cfargument name="createheaderrow" type="boolean" required="false" default="true" hint="flags whether or not create row of header values"> <cfargument name="delimiter" type="string" required="false" default="," hint="the field delimiter in csv value"> <!--- author: ben nadel link: http://www.bennadel.com/blog/1239-updated-converting-a-coldfusion-query-to-csv-using-querytocsv-.htm ---> ... </cffunction>
this using convert query csv. setting lstdatetimefields
argument correct field names caused them format correctly in excel file.
Comments
Post a Comment