this is a common missunderstanding we already have a solution for it,
but let me first explain what exactly is happening:
with this code:
<cfquery datasource="mydb" name="mytest">
INSERT INTO my_table(create_date)
VALUES(#createodbcdatetime(now())#)
</cfquery>
you send a SQL statement like this to the DB Server
INSERT INTO my_table(create_date)
VALUES({ts '2012-07-25 16:20:14'})
If Railo has set the the Timezone CST and the DB Server is running in PST you run into problems for a very simple reason. the Timestamp produced ({ts '2012-07-25 16:20:14'}) is based on the CST Timezone, this means it is "2012-07-25 16:20:14 CST", BUT the TimeZone information is not present in the timestamp.
so if the DB server is reading the string timestamp from the SQL String, it has no timezone information and the DB Server simply takes it own timezone for the timestamp, because it has no idea from whitch timezone the request is coming from, this means the db server interpret the timestamp as "2012-07-25 16:20:14 PST" what is 2 hours later.
then when you get this date back you get "2012-07-25 18:20:14 CST" what is exactly the same as "2012-07-25 16:20:14 PST", this means the failure happens when you send the string timestamp to the db server in a different timezone without the timezone information. this conversion problem does not happen when you get the date back via a select statement, simply because in this case the date is send in a timezone independent format.
how to solve?
the best solution is to send the date in a timezone independent format, for example this way
<cfquery datasource="mydb" name="mytest">
INSERT INTO my_table(create_date)
VALUES(<cfqueryparam value="#now()#" cfsqltype="CF_SQL_TIMESTAMP">)
</cfquery>
of course this solution perhaps need mny changes in existing code, so we did a better solution for this.
in the Railo admin go to your datasource declaration, in the detail view of your datasource, you can find the point "Timezone", simply set this to your DB Timezone and yo are fine!
Of course this has no affect on dates already stored, they are wrong in the db.
this setting will change the Environment timezone inside cfquery.
in addition you can also use the attribute "timezone" with the tag cfquerty:
<cfquery datasource="mydb" name="mytest" timezone="PST">
INSERT INTO my_table(create_date)
VALUES(#createodbcdatetime(now())#)
</cfquery>
/micha
--
/micha
Michael Offner CTO Railo Technologies GmbH