Hi all
This code works fine to set a value if there is no value in form.MEETING (so I can insert the value into my db with sql):
<cfset isMEETINGNull = iif(len(trim(form.MEETING)) EQ 0, true, false)>
How can I set the value to a date two days from now if it is empty(instead of null as it is at the moment, seomthing like this?)
<cfset isMEETINGNull = DateFormat(DateAdd("d", +2, Now()), "MM/DD/YYYY")>
Thank you!
Message was edited due to google research possible answer
if (len(trim(form.meeting)) > 0
theDate = dateAdd("d", 2, now();
else
theDate = something.
But it's not that simple. You might also have to ensure that form.meeting actually is a date and if so, that it meets whatever other criteria you have. Finally, don't use dateformat in this situation. It's a display function that returns a string. You want to send a date object to your db.
Thanks BKBK I put this code but I get an error:
<!--- UPDATE QUERY --->
<cfif isDefined("form.UPDATEADDBTN")>
<cfif FORM.ENTID GTE 1>
<cfset isCOMMENTSNull = iif(len(trim(form.COMMENTS)) EQ 0, true, false)>
<cfset meetingDate = trim(form.meeting)>
<cfif not isDate(meetingDate)>
<cfset meetingDate = dateAdd("d", 2, now())>
</cfif>
<CFQUERY name="updatecompany" datasource="salesdb">
update COMPANY
SET COMMENTS= <cfqueryparam cfsqltype="cf_sql_longvarchar" value="#trim(form.COMMENTS)#"
null="#isCOMMENTSNull#" />,
MEETING= <cfqueryparam cfsqltype="cf_sql_timestamp" value="#trim(form.MEETING)#"
null="#isMEETINGNull#" />,
WHERE ENTID = #FORM.ENTID#
</CFQUERY>
<cfelse>
Error:
75 : MEETING= <cfqueryparam cfsqltype="cf_sql_timestamp" value="#trim(form.MEETING)#" null="#isMEETINGNull#" />,
Ok thanks BKBK, I changed it to meetingDate:
MEETING= <cfqueryparam cfsqltype="cf_sql_timestamp" value="#trim(form.MEETING)#"
null="#meetingDate#" />
I now get this error:
Cannot convert the value of type class coldfusion.runtime.OleDateTime to a boolean
75 : MEETING= <cfqueryparam cfsqltype="cf_sql_timestamp" value="#trim(form.MEETING)#" null="#meetingDate#" />,
In my database MEETING is a varchar field, length 255, decimals 0 and allow null. Default: NULL, character set: utf8
I tried to change it to timestamp in my mysql program but it doesn't let me (maybe because I already have value in that field? I can delete the column and create it again there if required)
goodychurro1 wrote:
Ok thanks BKBK, I changed it to meetingDate:
No, you didn't!
MEETING= <cfqueryparam cfsqltype="cf_sql_timestamp" value="#trim(form.MEETING)#"
null="#meetingDate#" />
I said nothing about nulls. Here it is again: MEETING = <cfqueryparam cfsqltype="cf_sql_timestamp" value="#meetingDate#"/>
I wouldn't go changing many things at once. That would lead to complexity. Start with your original code, and just tweak it a little, using the suggestions. For example
<!--- UPDATE QUERY --->
<cfif isDefined("form.UPDATEADDBTN")>
<cfif FORM.ENTID GTE 1>
<cfset isCOMMENTSNull = iif(len(trim(form.COMMENTS)) EQ 0, true, false)>
<cfset meetingDate = trim(form.meeting)>
<cfif not isDate(meetingDate)>
<cfset meetingDate = dateAdd("d", 2, now())>
<cfelse>
<!--- Here, apply Dan's advice to convert from string to datetime object. Use, for example, parseDatetime, createdate or createdatetime --->
<cfset meetingDate = parseDatetime(meetingDate)>
</cfif>
<CFQUERY name="updatecompany" datasource="salesdb">
update COMPANY
SET COMMENTS = <cfqueryparam cfsqltype="cf_sql_longvarchar" value="#trim(form.COMMENTS)#" null="#isCOMMENTSNull#" />,
MEETING = <cfqueryparam cfsqltype="cf_sql_timestamp" value="#meetingDate#" />
WHERE ENTID = <cfqueryparam cfsqltype="cf_sql_integer" value="#FORM.ENTID#" />
</CFQUERY>
<cfelse>
Dan Bracuk wrote:
Regarding, "
I get this error in coldfusion?:
Cannot convert the value of type class coldfusion.runtime.OleDateTime to a boolean"
What is the line of code creating this error?
The error was caused by the attribute null="#meetingDate#". I had suggested that this attribute be left out altogether.
North America
Europe, Middle East and Africa
Asia Pacific