Copy link to clipboard
Copied
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')#
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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 | |||
|
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
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>
Find more inspiration, events, and resources on the new Adobe Community
Explore Now