I am at the liberty of a certain database, which stores date values as integers (i.e. 20121119). I have several queries that retrieve these values for reporting displays, so I need to convert these values to m/d/yyyy format.
I see several ways to do this:
- Do the conversion in the display, using an existing global UDF. The drawback here, is that if the query is re-used, I need to duplicate the code necessary to convert the display value.
- Parse the value in the SQL to return a properly formatted value. I’m reading from a DB2/iSeries, which does not (as far as I have found) have a built-in function for this.
-
Loop over the result set and convert each value one at a time. This is what I am currently doing, however for larger data-sets, performance is an issue:
<cfscript> var i = 1; var _query = ARGUMENTS.query; if ( !Len(Trim(ARGUMENTS.column)) || !ListFindNoCase(_query.ColumnList, ARGUMENTS.column)) return _query; for (i=1; i<=_query.RecordCount; i++) { _query[ARGUMENTS.column][i] = VARIABLES.Library.DateTime.ParseAS400Date( _query[ARGUMENTS.column][i] ); } return _query; </cfscript>
Is there an easy/quick way to apply a formatting function to an entire column in a ColdFusion query object?
As noted by @Dan, there is a built-in function that will convert a string to a timestamp representation. Since you have an int, then it would be something like this: