Friday, October 10, 2008    
Home My Books Blog ColdFusion About Me Back    

Calendar
<< Aug 2006 >>
S M T W T F S
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Search

Categories
 • Acrobat (2) [RSS]
 • Adobe (68) [RSS]
 • AdobeMAX06 (45) [RSS]
 • AdobeMAX07 (59) [RSS]
 • AdobeMAX08 (25) [RSS]
 • AIR (134) [RSS]
 • Appearances (122) [RSS]
 • Books (69) [RSS]
 • CFEclipse (14) [RSS]
 • ColdFusion (1154) [RSS]
 • Data Services (13) [RSS]
 • Fish Tank (2) [RSS]
 • Flash (106) [RSS]
 • Flex (372) [RSS]
 • Home Automation (3) [RSS]
 • Jobs (96) [RSS]
 • JRun (13) [RSS]
 • Labs (27) [RSS]
 • LiveCycle (22) [RSS]
 • MAX (160) [RSS]
 • Regular Expressions (13) [RSS]
 • RIA (11) [RSS]
 • SQL (38) [RSS]
 • Stuff (505) [RSS]
 • Tips (CF Studio) (80) [RSS]
 • Tips (CF) (795) [RSS]
 • Tips (Dreamweaver) (91) [RSS]
 • Tips (Flex Builder) (2) [RSS]
 • Using CF (137) [RSS]
 • Wireless (99) [RSS]

Other BLOGs
 • Charlie Arehart
 • Lee Brimelow
 • Ray Camden
 • Christophe Coenraets
 • Sean Corfield
 • Mihai Corlan
 • Cornel Creanga
 • John Dowdell
 • Danny Dura
 • Enrique Duvos
 • Steven Erat
 • Kevin Hoyt
 • Serge Jespers
 • Adam Lehman
 • Duane Nickull
 • Miti Pricope
 • Andrew Shorten
 • Ryan Stewart
 • James Ward
 • Greg Wilson
 • Full As A Goog

RSS Feeds
 • Feed
 • Subscribe

Join my mailing list and find out about new books and other topics of interest.

Thoughts, ideas, tips, musings, and pontifications (not necessarily in that order) by Ben Forta ...
NOTE: This is my personal blog, and the opinions and statements voiced here are my own.

Viewing By Entry / Main
August 29, 2006

Simple ColdFusion Date Difference Calculations

DateDiff() is usually used to perform date difference calculations. But for simple difference calculations you can subtract dates from each other, like this:

<cfset mydate=CreateDate(2006,8,17)>
<cfoutput>#Now()-mydate# days since #DateFormat(mydate)#</cfoutput>

The returned number will likely not be an integer, and will contain date fractions too, so you may want to use Int() to round the number to just the integer portion:

<cfset mydate=CreateDate(2006,8,17)>
<cfoutput>#Int(Now()-mydate)#</cfoutput>

TrackBacks
There are no trackbacks for this entry.

No trackback URL. Trackbacks are only allowed via interactive form.

Comments
Along those same lines, people can simply subtract days from a date. Since integers (in many cases) are a valid form of fractional date as a whole as well as time spans, (ie. 1.0 = 1 day, 2.0 = 2 days) the math should work out nicely:

(Now() - 1) === > Yesterday
(Now() + 1) === > Tomorrow
# Posted By Ben Nadel | 8/29/06 11:23 AM
So then, doing date calculations in this manner always defaults to days as the unit, right? At least that's what it appears to be in the example.
# Posted By Doug Boude | 8/29/06 2:14 PM
Doug, correct.

--- Ben
# Posted By Ben Forta | 8/29/06 2:16 PM
Doug Hughes also found a nifty way to loop over dates. http://doughughes.net/index.cfm?event=viewEntry&am...
# Posted By Scott Stroz | 8/29/06 4:39 PM

  © Copyright 1997-2008 Ben Forta, All Rights Reserved