Skip to main content
Known Participant
November 2, 2006
Answered

DateAdd

  • November 2, 2006
  • 7 replies
  • 1412 views
#DateAdd('d', 30, Now())#
I wish to add date format mm/dd/yyyy to the code above
can anyone help?

what do i have to add
thanks
This topic has been closed for replies.
Correct answer
You can just use your dateAdd statement as though it's a normal date with the dateFormat function.

It would look something like this

#DateFormat(dateAdd("d", 30, now()), "mm/dd/yyyy")#

7 replies

Inspiring
August 15, 2008
A*** wrote:
> BST

this is funny ;-)

<cfscript>
setLocale("en_GB");
tz=createObject("java","java.util.TimeZone");
oldTZ=tz.getDefault();
bstTZ=tz.getTimezone("BST");
tz.setDefault(bstTZ);
writeoutput('#bstTZ.getDisplayName()#
#lsDateFormat(DateAdd("yyyy",3,createDate(1943,4,24)))#');
tz.setDefault(oldTZ);
</cfscript>

works but interestingly returns:
Bangladesh Time 24-Apr-1946

using "British Summer Time" as the tz ID still works:
Greenwich Mean Time 24-Apr-1946

i always wondered what all the tz ID squawking was all about, now i know ;-)

in any case, same results for cf7 & cf8.

i'd look at your server OS for this or might try a more update JVM (but stay in
the 1.4 version range as 1.5 & above will break stuff in cf7).
Inspiring
August 15, 2008
You have just given me an idea!
I will reset my tz...
I will let you know how it goes.
Many thanks.
Inspiring
August 15, 2008
BST
Inspiring
August 13, 2008
A*** wrote:
> Coldfusion 7,0,2,142559
> OS Windows 2000 Version 5.0
> Locale English (UK)

i tried en_GB, worked ok. i guess test the tz, what timezone is your server?
GMT? no DST involved?
Inspiring
August 14, 2008
isDSTon Yes
UtcHourOffset -1

I start to suspect possible corruption of some memory space...
Inspiring
August 13, 2008
Coldfusion 7,0,2,142559
OS Windows 2000 Version 5.0
Locale English (UK)
Inspiring
August 12, 2008
My idea is to never use strings as dates, even though they often work. Go with
#lsDateFormat(DateAdd("yyyy", 3, CreateDate(1980,4,24)))#
Inspiring
August 13, 2008
I have tried CreateDate for the year 1943 but it did not work i.e.
#lsDateFormat(DateAdd("yyyy", 3, CreateDate(1943,4,24)))#.

May be it is a server related issue. Other years affected are 1944, 1945 & 1947. All other years are OK even using the string style
#lsDateFormat(DateAdd('yyyy', 3, '24/04/1980'))# .

Many thanks.
Inspiring
August 12, 2008
dateAdd 3 years

#lsDateFormat(DateAdd('yyyy', 3, '24/04/1943'))# gives java.lang.IllegalArgumentException error while
#lsDateFormat(DateAdd('yyyy', 3, '24/04/1980'))# gives the correct result - 24-Apr-1983.
Any ideas, please...
Correct answer
November 3, 2006
You can just use your dateAdd statement as though it's a normal date with the dateFormat function.

It would look something like this

#DateFormat(dateAdd("d", 30, now()), "mm/dd/yyyy")#