Getting Data In

help with the dashboard time calculation needed

damucka
Builder

Hello,

I have relatively easy issue I am struggling with.
I would like to calculate the time difference in seconds between the form.to and form.from set from the time picker. The dashboard beginning looks as follows:

<form>
  <label>System KPI Dashboard Clone</label>
  <fieldset submitButton="false" autoRun="true">
    <input type="dropdown" token="sysid" searchWhenChanged="true">
      <label>System</label>
      <fieldForLabel>SYSYSID</fieldForLabel>
      <fieldForValue>SYSYSID</fieldForValue>
      <search>
        <query>| dbxquery query="select distinct sysysid from sapiop.zkpic_sysreltask where hana = 'X' order by sysysid" connection="HANA_MLBSO"</query>
        <earliest>-24h@h</earliest>
        <latest>now</latest>
      </search>
      <default>ISP</default>
    </input>
    <input type="time" token="field1" searchWhenChanged="true">
      <label>Time</label>
      <default>
        <earliest>-24h@h</earliest>
        <latest>now</latest>
      </default>
      <change>
        <eval token="form.from">strftime(relative_time(now(),'earliest'), "%F %T")</eval>
        <eval token="form.to">strftime(relative_time(now(),'latest'), "%F %T")</eval>
        <eval token="timediff">$form.to$ - "$form.from$</eval>
      </change>
    </input>
  </fieldset>
  <row>
    <panel depends="$hidden$">

However the timediff does not get set.
I tried different combinations with relative_time, etc. but is seems not to get set.
How would I do it?

Kind regards,
Kamil

0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

$form.to$ and $form.from$ are strings and you can't subtract strings. Use the integer form of each time, instead.

<eval token="timediff">relative_time(now(), 'latest') - relative_time(now(), 'earliest')</eval>
---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

richgalloway
SplunkTrust
SplunkTrust

$form.to$ and $form.from$ are strings and you can't subtract strings. Use the integer form of each time, instead.

<eval token="timediff">relative_time(now(), 'latest') - relative_time(now(), 'earliest')</eval>
---
If this reply helps you, Karma would be appreciated.
0 Karma

damucka
Builder

I solved the issue, was actually not that difficult ...

<eval token="form.from">strftime(relative_time(now(),'earliest'), "%Y-%m-%d %H:%M:%S")</eval>
<eval token="form.to">strftime(relative_time(now(),'latest'), "%Y-%m-%d %H:%M:%S")</eval>
<eval token="timediff">strptime($form.to$, "%Y-%m-%d %H:%M:%S")  - strptime($form.from$, "%Y-%m-%d %H:%M:%S")</eval> 
0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...