User Guide

Table Of Contents
Data type conversion 63
Date-time functions and queries when ODBC is not supported
Many CFML functions, including the Now, CreateDate, CreateTime, and CreateDateTime
functions, return date-time objects. ColdFusion creates Open Database Connectivity (ODBC)
timestamp values when it converts date-time objects to strings. As a result, you might get
unexpected results when using dates with a database driver that does not support ODBC escape
sequences, or when you use SQL in a query of queries.
If you use SQL to insert data into a database or in a WHERE clause to select data from a
database, and the database driver does not support ODBC-formatted dates, use the
DateFormat
function to convert the date-time value to a valid format for the driver. This rule also applies to
queries of queries.
For example, the following SQL statement uses the
DateFormat function in a query of queries to
select rows that have MyDate values in the future:
<cfquery name="MyQofQQ" dbtype="query">
SELECT *
FROM DateQuery
WHERE MyDate >= '#DateFormat(Now())#'
</cfquery>
The following query of queries fails with the error message “Error: {ts is not a valid date,” because
the ColdFusion
Now function returns an ODBC timestamp:
<cfquery name="MyQofQQ" dbtype="query">
SELECT *
FROM DateQuery
WHERE MyDate >= '#now()#'
</cfquery>
Using JavaCast with overloaded Java methods
You can overload Java methods so a class can have several identically named methods that differ
only in parameter data types. At runtime, the Java virtual machine attempts to resolve the specific
method to use, based on the types of the parameters passed in the call. Because ColdFusion does
not use explicit types, you cannot predict which version of the method the virtual machine will
use.
The ColdFusion
JavaCast function helps you ensure that the right method executes by
specifying the Java type of a variable, as in the following example:
<cfset emp.SetJobGrade(JavaCast("int", JobGrade))>
The JavaCast function takes two parameters: a string representing the Java data type and the
variable whose type you are setting. You can specify the following Java data types: bool, int, long,
float, double, and String.
For more information on the
JavaCast function, see CFML Reference.