Skip to main content
October 19, 2009
Question

How do I get "#" round dates in an "Insert into " query

  • October 19, 2009
  • 2 replies
  • 979 views

I am trying to use the "Insert Into" type "CFQUERY" and insert a date into a field.This date has been input by the user on a web form using the syntax "<input type="text" name="DateInTheatres"...>
The query is
<CFQuery datasource="blah">
Insert into Films(<other fields>,DateInTheatres)
values(<other fields>,#CreateODBCDate(Form.DateInTheatres)#)
</CFQuery>
The above code does not seem to work because the "#" are not automatically put to the left & right of the date so when the sql resolves you get 12/10/2009 (for example) no quotes, nothing.
How can I fix this?
many thanks
Paul 

    This topic has been closed for replies.

    2 replies

    Ken_Ford_-_ACP-QFo4AB
    Inspiring
    October 19, 2009

    Try something like this:

    <cfquery name="someName" datasource="someDatasource">
    INSERT INTO Films
    (SomeField, DateInTheatres)
    VALUES
    (
    <cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.SomeField#">,
    <cfqueryparam cfsqltype="cf_sql_date" value="#FORM.DateInTheatres#">
    )
    </cfquery>

    Ken Ford

    October 19, 2009

    Thanks very much Ken - I'll try that out!

    Inspiring
    October 19, 2009

    Have a look @ the docs for <cfqueryparam>.

    --

    Adam

    October 19, 2009

    Thanks for this but not really helpful - if you know the answer,

    just lay the code solution on me!

    cheers

    Inspiring
    October 19, 2009

    In what way is it "not helpful"?  It's the answer.

    If you can't be bothered reading a couple of paragraphs of docs and actually learn something, why should anyone be arsed writing your code for you?  Indeed doing your job for you?  I presume you're getting paid for this?

    --

    Adam