dateadd()

Adds time (years, months, weeks, days, hours, minutes, and seconds) to the current date-time.

Syntax

dateadd(DATE, "{year|mon|day|hour|min|sec|msec}", INT)
Required Parameter
DATE
Expression that returns the time type.
"{year|mon|day|hour|min|sec|msec}"
Time unit to add to the INT value, enclosed in a pair of double quotes(" "). For the meaning of each unit of time, refer to the table below.

Unit of Time

Unit of TimeDescription
yearYear
monMonth
dayDay
hourHour
minMinute
secSecond
msecMillisecond
INT
Integer value to add to the date in the given units.

Usage

json "{}" 
| eval
    _time           = date("2013-09-28 11:47:00", "yyyy-MM-dd HH:mm:ss"),
    add_1_year      = dateadd(date("2013-09-28 11:47:00", "yyyy-MM-dd HH:mm:ss"), "year", 1),
    subtract_1_mon  = dateadd(date("2013-09-28 11:47:00", "yyyy-MM-dd HH:mm:ss"), "mon", -1),
    subtract_3_days = dateadd(date("2013-09-28 11:47:00", "yyyy-MM-dd HH:mm:ss"), "day", -3),
    add_2_hours     = dateadd(date("2013-09-28 11:47:00", "yyyy-MM-dd HH:mm:ss"), "hour", 2),
    input_null      = dateadd(null, "sec", 10),
    input_str       = dateadd("invalid", "sec", 10)