Skip to main content
Known Participant
July 17, 2013
Question

How to get date 30 days from existing date?

  • July 17, 2013
  • 2 replies
  • 1035 views

I found this codes from this forum: 

#dateformat(dateadd('d', 30, now()),'dd-mmm-yyyy h:mm:ss')# This code works but unfortunately I'm not using Now(). Instead I need to use a user entered Date such as Departure Date, something like 07/06/2013



When I use the above code with my DepartureDate instead of Now() I got a java.util.date error

#dateformat(dateadd( "d", 30, "DepartureDate" ),'dd-mmm-yyyy h:mm:ss')#

When I get rid of the double quotes in 3rd parameter, I did not get error but the result date is wrong:



When DepartureDate is 07/16/2013,I got 08/30/2013

How can I easily add 30 days to my DepartureDate?

Thanks

#dateformat(dateadd( "d", 30, DepartureDate ),'dd-mmm-yyyy h:mm:ss')#

This topic has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
July 17, 2013

alecken wrote:

When DepartureDate is 07/16/2013 ...

How can I easily add 30 days to my DepartureDate?

#dateformat(dateadd( "d", 30, DepartureDate ),'dd-mmm-yyyy h:mm:ss')#

DateFormat expects a Date object as third argument, not a string. So go for something like this:

<cfset departureDate = createdate(2013,7,16)>

<cfoutput>#dateformat(dateadd( "d", 30, departureDate ),'dd-mmm-yyyy h:mm:ss')#</cfoutput>

p_sim
Participating Frequently
July 17, 2013

If the DepartureDate is a variable, don't wrap with quotes or double-quotes.

#dateformat(dateadd( "d", 30, DepartureDate ), "dd-mmm-yyyy h:mm:ss")#

What is the value of DepartureDate, by the way? You might need to use CreateDateTime() to convert the DepartureDate value.

aleckenAuthor
Known Participant
July 17, 2013

That's the thing. When I get rid of the double quotes on DepartureDate, I got this error (see below)

(DepartDate_1 is the DepartureDate)

It is a variable and the value is 07/31/2013

If I don't use the double quotes, I got this value: 30-Aug-2013 which is wrong. 30 days from July 16 is not August 30

I have converted DepartureDate using CreateODBCDate before using it in DateAdd function.

The following information is meant for the website developer for debugging purposes.
Error Occurred While Processing Request
 

Parameter validation error for the DATEADD function.

The value of parameter 3, which is currently DepartDate_1, must be a class java.util.Date value.

p_sim
Participating Frequently
July 17, 2013

You might be confused with the departureDate value.

From your first post:

07/16/2013 plus 30 days equals to 08/05/2013

From your last post:

07/31/2013 plus 30 days equals to 08/30/2013

Here's my test code:

<cfset departureDate = "07/16/2013" />

<cfoutput>#dateFormat(dateadd( "d", 30, DepartureDate ), "dd-mmm-yyyy h:mm:ss")#</cfoutput>