Converting relative date like "now-30d" to absolute date/time format

I am writing a plugin for Kibana. I want to display a chart:

<Chart>
  <Axis
    id="bottom"
    title={dateFormatter(startDate)}
    position={Position.Bottom}
    tickFormat={dateFormatter}
  />
  <Axis
    id="left"
    position={Position.Left}
    tickFormat={(d: any) =>
      Number(d).toFixed(0)
    }
  />
  <BarSeries
    id="data"
    xScaleType={ScaleType.Time}
    yScaleType={ScaleType.Linear}
    xAccessor={["x"]}
    yAccessors={["y"]}
    stackAccessors={["x"]}
    data={chartData}
  /> 
</Chart>

In the horizontal axis (the first Axis in the above code), I want to show the title as Date, for example, 12 August 2023. The date is got from the EUI Date picker. It has startDate and endDate. When the format in Date picker is relative (like "Last 30 days"), startDate and endDate are like "now-30d" and "now". This case, dateFormatter(startDate) returns "Invalid date". If the format in Date picker is changed to Absolute, then dateFormatter(startDate) is what I want: 12 August 2023.

So, if I can convert the relative date "now-30d" to absolute date, my problem will be solved. It seems that this kind of relative date is specific to elasticsearch.

So the question is how to convert relative time format like "now-30d" to absolute date/time format.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.