ES|QL : Adding Days to a Date

Hello,

I was wondering if its possible with ES|QL to use a date field and add x amount of days to create a new date field.

Or would a runtime field work for this?
Or would an ingest pipeline be the only solution.

Thanks,

Thanks for reaching out, @erikg. Would something like this work for you?

POST _query?format=txt
{
  "query": """
    ROW original_date = "2025-01-01T00:00:00.000Z"
    | EVAL dt       = TO_DATETIME(original_date)
    | EVAL dt_long  = TO_LONG(dt)                  
    | EVAL add_ms   = 5 * 24 * 60 * 60 * 1000         
    | EVAL new_long = dt_long + add_ms                 
    | EVAL new_date = TO_STRING(TO_DATETIME(new_long))
    | KEEP new_date
    | LIMIT 1
  """
}

The output you should get back is as follows:

        new_date        
------------------------
2025-01-06T00:00:00.000Z
2 Likes

Hey @jessgarson yes that would!
thanks!

1 Like

Thanks, @erikg! Glad this works for you.