Skip to Main Content
Programming ColdFusion MX, 2nd Edition
book

Programming ColdFusion MX, 2nd Edition

by Rob Brooks-Bilson
August 2003
Intermediate to advanced content levelIntermediate to advanced
1140 pages
68h 45m
English
O'Reilly Media, Inc.
Content preview from Programming ColdFusion MX, 2nd Edition

Name

DateAdd

Synopsis

                  
                  DateAdd(datepart, number, date)

Adds number to the datepart of the specified date. Dates must be in the range AD 100-9999. To subtract, make number negative. Valid entries for datepart are l (millisecond), s (second), n (minute), h (hour), ww (week), w (weekday), d (day), y (day of year), m (month), q (quarter), and yyyy (year). For information on how ColdFusion MX handles two-digit years, see CreateDate( ). Examples:

<cfset MyDateTime = Now( )>
   
<cfoutput>The original time and date is 
#TimeFormat(MyDateTime,'hh:mm:ss tt')#, #DateFormat(MyDateTime,'mmmm dd, yyyy')#
   
<p><b>Add 30 Seconds:</b> 
#TimeFormat(DateAdd('s', 30, MyDateTime),'hh:mm:ss tt')#
<br><b>Subtract 10 minutes:</b> 
#TimeFormat(DateAdd('n', -10, MyDateTime),'hh:mm:ss tt')#
<br><b>Add 2 hours:</b> 
#TimeFormat(DateAdd('h', 2, MyDateTime),'hh:mm:ss tt')#
<br><b>Add 9 weeks:</b> 
#DateFormat(DateAdd('ww', 9, MyDateTime),'mmmm dd, yyyy')#
<br><b>Add 3 weekdays:</b> 
#DateFormat(DateAdd('w', 3, MyDateTime),'mmmm dd, yyyy')#
<br><b>Subtract 67 days:</b> 
#DateFormat(DateAdd('d', -67, MyDateTime),'mmmm dd, yyyy')#
<br><b>Add 45 days of the year:</b> 
#DateFormat(DateAdd('y', 45, MyDateTime),'mmmm dd, yyyy')#
<br><b>Add 7 months:</b> 
#DateFormat(DateAdd('m', 7, MyDateTime),'mmmm dd, yyyy')#
<br><b>Add 2 quarters:</b> 
#DateFormat(DateAdd('q', 2, MyDateTime),'mmmm dd, yyyy')#
<br><b>Add 5 years:</b> 
#DateFormat(DateAdd('yyyy', 5, MyDateTime),'mmmm dd, yyyy')#
</cfoutput>
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming ColdFusion

Programming ColdFusion

Rob Brooks-Bilson

Publisher Resources

ISBN: 0596003803Supplemental ContentErrata Page