Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateFormat and DateAdd 1

Status
Not open for further replies.

greatfalls

Technical User
Jul 1, 2001
21
0
0
CA
I can get the current year;
<CFOUTPUT>#DateFormat(Now(),' yyyy')#</CFOUTPUT>

but then I am trying to display the year 2000

#DateAdd('YYYY', -1, Now())#</CFOUTPUT>

and I get {ts '2001-04-23 21:02:38'}

I don't see what is wrong with this?

 
I just pasted in your exact code, no modification and it worked fine:

<CFOUTPUT>
#DateFormat(Now(),' yyyy')#<BR><BR>
#DateAdd('YYYY', -1, Now())#
</CFOUTPUT>

Gave me:

2001

{ts '2000-07-02 18:52:22'}

Is there something else to the code that you've done to not get the correct year?
- tleish
 
I got that too. What I thought I was suppose to get was just the year.

2001, 2000, 1999

Why the brackets below. And how would I subtract a year and just display the year

{ts '2000-07-02 18:52:22'}

Thans much for your reply

 
There are several ways to do it, here are some examples all od which use DateAdd() function. The following examples should return:
2001
2000
1999

Year() Function
#Year(Now())#<BR>
#Year(DateAdd(&quot;YYYY&quot;, -1, Now()))#<BR>
#Year(DateAdd(&quot;YYYY&quot;, -2, Now()))#<BR><BR>

Year() Function - with preset variable vDate
<CFSET vDate = Now()>
#Year(vDate)#<BR>
<CFSET vDate = DateAdd(&quot;YYYY&quot;, -1, Now())>
#Year(vDate)#<BR>
<CFSET vDate = DateAdd(&quot;YYYY&quot;, -2, Now())>
#Year(vDate)#<BR><BR>

DateFormat() Function
#DateFormat(Now(),&quot;yyyy&quot;)#<BR>
#DateFormat(DateAdd(&quot;YYYY&quot;, -1, Now()),&quot;yyyy&quot;)#<BR>
#DateFormat(DateAdd(&quot;YYYY&quot;, -1, Now()),&quot;yyyy&quot;)#<BR><BR>

DateFormat() Function - with preset variable vDate
<CFSET vDate = Now()>
#DateFormat(vDate,&quot;yyyy&quot;)#<BR>
<CFSET vDate = DateAdd(&quot;YYYY&quot;, -1, Now())>
#DateFormat(vDate,&quot;yyyy&quot;)#<BR>
<CFSET vDate = DateAdd(&quot;YYYY&quot;, -2, Now())>
#DateFormat(vDate,&quot;yyyy&quot;)#<BR>
- tleish
 
tleish,

Thank you very much for your reply

Mar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top