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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add today's date to a month from now! 1

Status
Not open for further replies.

NEL3644

Technical User
Sep 4, 2000
26
US
I can easily add today's date to a week from now because I know that a week has exactly 7 days - just like this example:
<cfset ExpirationDate = now() + 7>

Now, what if I want to add today's date to a month from now, knowing that a month can have 28 and 29 (if month is Feb.) and 30 or 31 days for rest of the months?
 
You need to use the DateAdd function. For example, to add one month to the current date:

<cfset NewDate = DateAdd(&quot;m&quot;, 1, Now())>

This function can be used for any interval of time.

Andrew
amayer@sonic.net
 

You can also use the code above to subtract an amount of time from a date, by appending your number with a minus sign:

<cfset NewDate = DateAdd(&quot;m&quot;, -2, Now())>

Will return the current date minus two months. Coldfusion seems to automatically compensate for the differing amount of dates in months, eg if you subtract 4 months from the date 31st October 2002, the date returned will be 30th June 2002 (as June only has 30 days).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top