Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to get date 30 days from existing date?

Community Beginner ,
Jul 16, 2013 Jul 16, 2013

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')#

TOPICS
Getting started
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 16, 2013 Jul 16, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 17, 2013 Jul 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 17, 2013 Jul 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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 17, 2013 Jul 17, 2013
LATEST

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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources