Skip to main content
Version: 19

Relative Datetime

Sometimes a configuration may require to select, for example, all dossiers created “5 days ago”. This is hard to do when comparing to fixed dates. As a solution we have a “relative datetime”. To define a valid relative datetime you must follow these rules:

  • The string must start with either a < or > character. This indicates the direction of time to search in.
    • < means BEFORE the relative time,
    • > means AFTER the relative time.
  • Following the time direction is a summation of "time units" (optionally can be separated by whitespace). Each time unit consists of 2 parts:
    • a number with a leading plus or minus sign. + meaning in the future from now and - meaning in the past from now.
    • a character representing a temporal unit. See the table below for the supported units. There can be multiple time units and they can be specified in any order.
    • Example: 1 year 5 days from today => +1y +5d
      • Note: there can be multiple ways to define the same relative date. E.g. the above can also be configured as +2y -360d.
  • Some examples:
    • > +4h -30m -> any date after 3h 30m from now
    • < -1y-6M -> any date before 1 year and 6 months ago

Temporal Units​

  • y : years
  • M : months
  • d : days
  • h : hours
  • m : minutes
  • s : seconds

Step-by-step example:​

Use case: Find all dossiers older than 2,5 years.

  1. I suggest to start with the time unit part first. In this case, 2,5 years ago can be written as -2y -6M.
    If today was the 1st of January 2025, then that would mean 2,5 years ago is the 1st of July 2022.
    We can visualize this on a timeline:
    image-20241120-133225.png
  2. Now we have to determine the time direction. Do we want to include the dossiers before 2,5 years ago or after 2,5 years ago?
    In our use case, do we want the dossiers before the 1st of July 2022 or after?
    We can visualize this on our timeline:image-20241120-133800.png In our use case, we want the dossiers older than, so we go with BEFORE <.
  3. Combining this, we end up with the relative datetime string < -2y-6M for our use case!