johnbarrett
03/04/2022, 4:15 AM#CreateODBCDate(Now)#
However I get an error, so I know that this is wrong. Any help would be greatly appreciatedPatrick
03/04/2022, 4:45 AMCreateODBCDate(Now())
ageax
03/04/2022, 4:45 AMNow()
(note the parenthesis)? That should work.johnbarrett
03/04/2022, 6:32 AM"#CreateODBCDate(Now())#"
and it works! I have to be careful with my parenthesis.Adam Cameron
Adam Cameron
johnbarrett
03/05/2022, 12:29 AMPatrick
03/05/2022, 12:31 AMageax
03/05/2022, 3:41 AMCreateODBCDate()
IMO, (unless Adobe has replaced it with another function that returns a date only). For queries you could also use cfqueryparam and cfsqltype=date to trim the time. Though if you want both date and time, yeah now()
is the shortest routeAdam Cameron
DateTime instead, do you have a code example?Any expression that returns a DateTime object. eg, as someone mentioned:
now
returns a DateTime. So does createDate
. So do most date functions (other than the ones that convert a date to something else, obvs.)
The functions with "ODBC" in their names are designed for converting DateTime objects to a format ODBC understands. Which is seldom a requirement these days.
(Although I just checked, and they don't seem to actually do what they claim these days anyhow: createOdbcDateTime
just returns a DateTime object (coldfusion.runtime.OleDateTime
), and createOdbcDate
returns a coldfusion.runtime.OleDate
)johnbarrett
03/07/2022, 1:16 AM<cfquery result="qResult"> INSERT INTO users
(
first_name,
last_name,
email,
joining_date
)
VALUES
(
<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.first_name#">
, <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.last_name#">
, <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.member_email#">
, <cfqueryparam cfsqltype="cf_sql_timestamp" value="#Now()#">
)
</cfquery>
Adam Cameron
queryExecute
rather than <cfquery>
to get rid of some of the code-bloat, but that is the correct approach, yes.
I would not use hungarian notation (-ish) on my variable names though (eg: qResult
)Adam Cameron
result
doesn't impart much information to the person reading the code. Also... an INSERT
query doesn't ever return anything in there anyway, does it? What are you using it for?