Skip navigation
Currently Being Moderated

Pass variable in Dateadd() function

May 17, 2013 10:49 PM

Tags: #dateadd



I want pass a variable for number part in Dateadd() funtion instead of hardcoding it.



<cfset var a = 180>


now i want to pass this value of a into "number" part of dateadd function.


DateAdd("d", number, now())


How can be this done..?

  • Currently Being Moderated
    May 18, 2013 1:17 AM   in reply to gokul1242

    <cfset var a = 180>

    <cfset newDate = DateAdd("d", a, now())>

    Mark as:
  • Currently Being Moderated
    May 19, 2013 12:18 PM   in reply to gokul1242

    gokul1242 wrote:


    i tried that....

    No, you didn't. What you tried is equivalent to:


    <cfset txt_expiration = "">

    <cfset yearAhead = DateAdd("d", txt_expiration, now())>


    You will find that the following does work:


    <cfset txt_expiration = 180>

    <cfset yearAhead = DateAdd("d", txt_expiration, now())>

    Mark as:
  • Currently Being Moderated
    May 20, 2013 2:17 AM   in reply to gokul1242

    Javascript runs on the browser, ColdFusion on the server. Hence, Javascript variables are not available to ColdFusion.


    You are apparently aware of one way of passing the variable to ColdFusion, namely, by submitting a form. The variable is then available on the form's action page as form.txt_expiration.


    However, I was wondering why don't just do the obvious. Get the value of txt_expiration directly from the query!

    Mark as:
  • Currently Being Moderated
    May 20, 2013 11:57 AM   in reply to gokul1242

    Run the following test. I hope everything will then become clear. Both CFM pages are within the same directory.





      function fnselectcat()

      {     document.frm.txt_expiration.value = 'KARAMBA!';





    <body onload="fnselectcat()" >

    <form name="frm" method="post" action="testActionpage.cfm">

        <input name="txt_expiration" type="text">






    <cfif isdefined("form.txt_expiration")>

       The form has been submitted and the value of  form.txt_expiration is: <cfoutput>#form.txt_expiration#</cfoutput>


    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