Spec-Zone.ru › ColdFusion

dateDiff

Determines the integer number of datepart units by which date1 is less than date2.

dateDiff(datepart, date1, date2) → returns numeric

Member Function Syntax

date2.diff(datepart, date1)

  • CF
  • Lucee
  • BL 1.0.0+
  • See Also: dateadd dateformat

    Argument Reference

    datepart string
    Required

    yyyy: Year q: Quarter m: Month y: Day of year d: Day w: Week (Weekday cf2018+) ww: Week h: Hour n: Minute s: Second
    Values:
    • yyyy
    • q
    • m
    • y
    • d
    • w
    • ww
    • h
    • n
    • s

    date1 date
    Required

    The smaller date to diffCan be either a string or a date object whereas member function only accept the latter

    date2 date
    Required

    The bigger date to diffCan be either a string or a date object whereas member function only accept the latter

    Compatibility

    ColdFusion:

    Member function is available in CF11+.

    Lucee:

    Member function is available in Lucee4.5+. The Lucee member function diffs dates in the opposite direction (+/-) than the Adobe CF member function. See the example below. This behaviour was changed in Lucee 6.0.0.130 to match ACF.

    Examples
    Sample code invoking the dateDiff function

    dateDiff Example

    Find the difference between two dates.

    dateDiff("d", "2013-01-15", "2013-01-25")

    Expected Result: 10

    How old are they?

    Calculates a persons age based on a variable birthDate which contains a date. Uses the now function to get current date.

    birthDate = createDate( 1972, 5, 20 );
    age = dateDiff('yyyy', birthDate, now());
    writeoutput( age );

    dateDiff member function

    Note the different behavior between ColdFusion and Lucee.

    testDate = now();
    diffDate = dateAdd('d', 1, testDate);
    writeOutput(testDate.diff('d', diffDate)); // this returns 1 on Lucee, and -1 on ColdFusion

    © 2012–present Foundeo, Inc. and the CFDocs contributors.
    Licensed under the MIT License.
    ColdFusion is a trademark of Adobe Systems Incorporated.
    https://cfdocs.org/datediff

    Spec-Zone.ru

    Настройки Оффлайн Что нового Помощь О нас
    Spec-Zone .ru
    спецификации, руководства, описания, API