Skip to main content
gokul1242
Inspiring
May 18, 2013
Question

Pass variable in Dateadd() function

  • May 18, 2013
  • 1 reply
  • 1672 views

Hi,

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

Eg:

<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..?


This topic has been closed for replies.

1 reply

BKBK
Community Expert
Community Expert
May 18, 2013

<cfset var a = 180>

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

gokul1242
gokul1242Author
Inspiring
May 19, 2013

i tried that.but getting error

BKBK
Community Expert
Community Expert
May 19, 2013

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())>