Updated on 2025-12-04 GMT+08:00

Date and Time Offset

  1. Processing functions
    • The parameters of the dt_add function are as follows:
      dt_add(field name, dt1=None, dt2=None, year(s)=None, month(s)=None, day(s)=None, hour(s)=None, minute(s)=None, second(s)=None, microsecond(s)=None, weeks(s)=None, weekday=None)

      Parameters such as year(s), month(s), and day(s) are followed by s, indicating that these parameters can be in two forms, that is, year and years, month and months. Take year and years as an example. If the value of year is transferred, the value of year is overwritten at the year granularity. If the value of years is transferred, the value of years is added at the year granularity. The dt_add function that is used together with the dt_add function can modify (add, reduce, or overwrite) the date and time values at a specific time granularity.

    • The weekday parameter in dt_add is usually used together with the dt_MO and dt_TU parameters to indicate the offset of a specific day of a week, as shown in the following examples.
  2. Scenario 1: Offset a date by year and month.
    • Raw log
      {
          "time1" : "2019-06-04 2:41:26"
      }
    • Processing rule 1
      e_set("time2", dt_add(v("time1"), year=2018))
    • Processing result 1
      {
      	"time1": "2019-06-04 2:41:26",
      	"time2": "2018-06-04 02:41:26"
      }
    • Processing rule 2
      e_set("time2", dt_add(v("time1"), years=2018))
    • Processing result 2
      {
      	"time1": "2019-06-04 2:41:26",
      	"time2": "4037-06-04 02:41:26"
      }
  3. Scenario 2: Offset a date by week.
    • Raw log: 2019-06-04 is Tuesday.
      {
          "time1" : "2019-06-04 2:41:26"
      }
    • Processing rule
      # Date of the next Monday of time1
      e_set("nex_Monday", dt_add(v("time1"), weekday=dt_MO(1)))
      
      # Date of the previous Tuesday of time1
      e_set("previous_Tuesday", dt_add(v("time1"), weekday=dt_TU(op_neg(1))))
      
      # Date of the Saturday after next of time1
      e_set("nex_next_Saturday", dt_add(v("time1"), weekday=dt_SA(2)))
      
      # Date of the Sunday before last from time1
      e_set("previous_previous_Sunday", dt_add(v("time1"), weekday=dt_SU(op_neg(2))))
    • Processing result
      {
      	"time1": "2019-06-04 2:41:26",
      	"previous_Tuesday": "2019-05-28 02:41:26",
      	"previous_previous_Sunday": "2019-05-26 02:41:26",
      	"nex_next_Saturday": "2019-06-15 02:41:26",
      	"nex_Monday": "2019-06-10 02:41:26"
      }