createodbcdatetime() function.

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default createodbcdatetime() function.

    Hi everyone,

    if I use the following;
    <cfset mydatetime = #createodbcdatetime(now())#>

    and try to insert the "mydatetime" value into a MS-SQL Database, the DB throws
    an error about the value not meeting the datetime columns length or some such
    error.

    I thought the whole idea of the createodbc function set was to create
    date/time values that were DB friendly.
    What am I missing??



    HeloWorld Guest

  2. Similar Questions and Discussions

    1. Error when using createODBCDateTime and Now()
      I'll start you guys off with my code here: <cfquery datasource="tempData"> UPDATE login SET lastLoginIP='#REMOTE_ADDR#' lastLoginDate=#Now()#...
    2. #25866 [Bgs]: Using error_reporting() function don't change output of phpinfo() function
      ID: 25866 Updated by: sniper@php.net Reported By: sfournier at dmsolutions dot ca Status: Bogus Bug Type: ...
    3. #25866 [Opn->Bgs]: Using error_reporting() function don't change output of phpinfo() function
      ID: 25866 Updated by: sniper@php.net Reported By: sfournier at dmsolutions dot ca -Status: Open +Status: ...
    4. note 33575 added to function.register-shutdown-function
      If your script exceeds the maximum execution time, and terminates thusly: Fatal error: Maximum execution time of 20 seconds exceeded in - on line...
    5. note 33132 deleted from function.register-shutdown-function by sniper
      Note Submitter: markus@malkusch.de ---- I can't agree with nick at nickjoyce dot com. I use php 4.2.3 on linux and my shutdown function is...
  3. #2

    Default Re: createodbcdatetime() function.

    I never use the createodbcsomething functions. I always do this sort of thing,
    and I probably have the wrong timeformat.

    datetimestring = dateformat(now(), "yyyy-mm-dd" & " " & timeformat(now(),
    "HH:MM:ss";

    (should resemble 2005-09-06 20:53:00)

    Then in the query, do something like this:

    insert into thetable
    (datetimefield, etc)
    values
    ( {ts '#datetimestring#'}, etc)



    Dan Bracuk Guest

  4. #3

    Default Re: createodbcdatetime() function.

    Originally posted by: Dan Bracuk
    I never use the createodbcsomething functions. I always do this sort of
    thing, and I probably have the wrong timeformat.

    datetimestring = dateformat(now(), "yyyy-mm-dd" & " " & timeformat(now(),
    "HH:MM:ss";

    (should resemble 2005-09-06 20:53:00)

    Then in the query, do something like this:

    insert into thetable
    (datetimefield, etc)
    values
    ( {ts '#datetimestring#'}, etc)



    Using your code and adding in the "{ts...} " is the problem I am having.
    the "{ts}" needs to be removed from the string prior to being inserted into
    the MS-SQL db, otherwise it fails.



    HeloWorld Guest

  5. #4

    Default Re: createodbcdatetime() function.

    Originally posted by: HeloWorld
    Using your code and adding in the "{ts...} " is the problem I am having.
    the "{ts}" needs to be removed from the string prior to being inserted into
    the MS-SQL db, otherwise it fails.


    I've used createODBCDate() and createODBCDateTime() with MS SQL for years and
    it works fine. Although, Dan Bracuk's date format looks pretty similar to
    ODBC format. Just make sure you're not putting single quotes around the
    variable values. It should look something like this

    <!--- don't need # pounds signs around the CF functions --->
    <cfset mydatetime = createodbcdatetime(now())>

    <cfquery .... >
    INSERT INTO yourTable (someDateColumn)
    VALUES (#myDateTime#)
    </cfquery>




    mxstu Guest

  6. #5

    Default Re: createodbcdatetime() function.

    Seems that I should take myself out the back and slap me around a little.....

    I am not too sure how it works, but it does....

    Ultimately , I believed it wasn;t working due to the following.

    when I CFOUPUTted the variable, it displayed as {ts'sxxxx'}
    I tried ti cut/paste THIS value directly into the SQL database (for testing to
    see if it worked!)
    which it didn't.

    performing a SQL insert, somehows strips out the {ts' '} and just leaves
    you with the date/time.


    HeloWorld Guest

  7. #6

    Default Re: createodbcdatetime() function.

    I think that's what everyone thinks the first time they see that funky date/time format... "This can't *possibly* work right..." ;-)
    mxstu Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139