Skip navigation
Currently Being Moderated

Set a date two days in the future

May 23, 2012 4:26 PM

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

 
Replies
  • Currently Being Moderated
    May 23, 2012 6:03 PM   in reply to goodychurro1

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    May 24, 2012 2:46 AM   in reply to goodychurro1

    Here is yet another suggestion. It includes validation.

     

    <cfset meetingDate = trim(form.meeting)>

    <cfif not isDate(meetingDate)>

    <cfset meetingDate = dateAdd("d", 2, now())>

    </cfif>

     

    The value to store in the database is then meetingDate.

     
    |
    Mark as:
  • Currently Being Moderated
    May 24, 2012 8:38 AM   in reply to goodychurro1

    I said, "The value to store in the database is then meetingDate". You yourself say, implicitly, at least, that there will be no null meetingDates. I therefore expected to see

     

    MEETING = <cfqueryparam cfsqltype="cf_sql_timestamp" value="#meetingDate#"/>

     
    |
    Mark as:
  • Currently Being Moderated
    May 24, 2012 9:15 AM   in reply to goodychurro1

    Whatever you have to do to change that field from varchar to timestamp, do it.

     
    |
    Mark as:
  • Currently Being Moderated
    May 24, 2012 9:29 AM   in reply to goodychurro1

    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#"/>

     
    |
    Mark as:
  • Currently Being Moderated
    May 24, 2012 10:13 AM   in reply to goodychurro1

    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>

     
    |
    Mark as:
  • Currently Being Moderated
    May 24, 2012 12:42 PM   in reply to goodychurro1

    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?

     
    |
    Mark as:
  • Currently Being Moderated
    May 24, 2012 11:01 PM   in reply to Dan Bracuk

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points