Skip to main content
March 30, 2011
Answered

date and datetime types with cfqueryparam

  • March 30, 2011
  • 1 reply
  • 11703 views

How do you get a date and a datetime type into a table with cfqueryparam ?

For date  I have tried <cfqueryparam value=#createodbcdate(thedate)# cfsqltype="CF_SQL_DATE" maxlength="23" null="yes"> and got NULL in the table.

For time I tried <cfqueryparam value=#now()# cfsqltype="CF_SQL_TIME" maxlength="23" null="yes"> but the date part of the datetime value was 1970-01-01.

In the table, types for these columns are datetime.

This topic has been closed for replies.
Correct answer -__cfSearching__-

As the name implies, cf_sql_date only inserts the date. Any time value is truncated. To insert both date and time use cf_sql_timestamp.

For date  I have tried <cfqueryparam

value=#createodbcdate(thedate)# cfsqltype="CF_SQL_DATE"

maxlength="23" null="yes"> and got NULL in the table.

That is what null="yes" means. It instructs CF to ignore the "value" and insert a NULL instead. Only use it if that is the desired result.

1 reply

-__cfSearching__-Correct answer
Inspiring
March 30, 2011

As the name implies, cf_sql_date only inserts the date. Any time value is truncated. To insert both date and time use cf_sql_timestamp.

For date  I have tried <cfqueryparam

value=#createodbcdate(thedate)# cfsqltype="CF_SQL_DATE"

maxlength="23" null="yes"> and got NULL in the table.

That is what null="yes" means. It instructs CF to ignore the "value" and insert a NULL instead. Only use it if that is the desired result.

March 30, 2011

Thank you. Hope no more questions for this.