Spec-Zone.ru › ColdFusion

dateAdd

Adds units of time to a date.

dateAdd(datepart, number, date) → returns date

Member Function Syntax

date.add(datepart, number)

  • CF
  • Lucee
  • BL 1.0.0+
  • See Also: dateConvert datePart createTimeSpan createDate dateDiff

    Argument Reference

    datepart string
    Required

    yyyy - Yearq - Quarterm - Monthy - Day of yeard - Dayw - Week dayww - Weekh - Hourn - Minutes - Secondl - Millisecond
    Values:
    • yyyy
    • q
    • m
    • y
    • d
    • w
    • ww
    • h
    • n
    • s
    • l

    number numeric
    Required

    The number of datepart units to add to the provided date. Number must be an integer. Negative integers move the date into the past, positive into the future.

    date date
    Required

    A datetime object in the range of 100AD-9999AD. NOTE: When passing a datetime object as a string, enclose it in quotation marks. Otherwise, it is interpreted as a numeric representation of a datetime object.

    Compatibility

    ColdFusion:

    Member function is available in CF11+.

    Lucee:

    Member function is available in Lucee4.5+

    Examples
    Sample code invoking the dateAdd function

    Add Days to a Date

    Add 30 days to August 3rd, 2014.

    dateAdd('d', 30, '8/3/2014')

    Expected Result: {ts '2014-09-02 00:00:00'}

    Subtract Days from a Date

    Subtract 30 days from August 3rd, 2014.

    dateAdd('d', -30, '8/3/2014')

    Expected Result: {ts '2014-07-04 00:00:00'}

    Add Weeks to a Date

    Here we're adding 8 weeks to the date August 3rd, 2014.

    dateAdd('ww', 8, '8/3/2014')

    Expected Result: {ts '2014-09-28 00:00:00'}

    Add Days to a Date (Member Function)

    Here we're adding 1 day to the current date/time.

    createDate( 2022, 10, 1 ).add( 'd', 1 )

    Expected Result: {ts '2022-10-02 00:00:00'}

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

    Spec-Zone.ru

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