AdobeStock_455007340

Simple ColdFusion Date Difference Calculations

Home » 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:

#Now()-mydate# days since #DateFormat(mydate)#

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:

#Int(Now()-mydate)#

4 responses to “Simple ColdFusion Date Difference Calculations”

  1. Ben Nadel Avatar
    Ben Nadel

    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

  2. Doug Boude Avatar
    Doug Boude

    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.

  3. Ben Forta Avatar
    Ben Forta

    Doug, correct.
    — Ben

  4. Scott Stroz Avatar
    Scott Stroz

    Doug Hughes also found a nifty way to loop over dates. http://doughughes.net/index.cfm?event=viewEntry&entryId=194

Leave a Reply