Skip to main content
November 13, 2008
Question

cf procs

  • November 13, 2008
  • 3 replies
  • 862 views
Hi i am tring to pass a date to ms sql via cfproc i have add in param as

<cfprocparam type="In" cfsqltype="CF_SQL_DateTime" dbvarname="InvoiceDate" value="#DateFormat(CreateODBCDate(form.txtInvoiceDate), "dd-mm-yyyy")#" null="No">

but i am getting a varchar to datetime exeption

any ideas?
This topic has been closed for replies.

3 replies

Inspiring
November 13, 2008
createdate()
Inspiring
November 13, 2008
> <cfprocparam type="In" cfsqltype="CF_SQL_DateTime" dbvarname="InvoiceDate"
> value="#DateFormat(CreateODBCDate(form.txtInvoiceDate), "dd-mm-yyyy")#"
> null="No">
>
> but i am getting a varchar to datetime exeption

If it's after a date, why are you passing it a string? dateFormat() is for
converting a date into a string, which you'd only generally do when
outputting the date for a human.

Pass the DB a date.

PS: the dbvarname attribute of <cfprocparam> is not supported on most
recent versions of CF. This is probably not relevant to your situation,
but it's worth bearing in mind.

--
Adam
November 13, 2008
ok thanks,

but i need to pass the format from a form field

dd-mm-yyyy
so whats the best way to convert this to a date?
Inspiring
November 13, 2008
Try this
<cfprocparam type="In" cfsqltype="CF_SQL_TIMESTAMP" value="#DateFormat(form.txtInvoiceDate, 'dd-mm-yyyy')#" null="No">

Note:
The MS SQL server datatype DATETIME maps to CF_SQL_TIMESTAMP.
Removed CreateODBCDate function call
Corrected nested quotes in value attribute contents
The dbvarname attribute is no longer supported
You may also try a date format string 'yyyy-mm-dd' or 'mm-dd-yyyy' depending on the configuration of your SQL server

http://msdn.microsoft.com/en-us/library/ms189491.aspx