Getting Data In

Subtracts two time field showing null result

Manasi25
Explorer

Hi,

 

i have my query below, i used query from "Solved" questions on community, however its showing NULL result for me.

Query --

index=victorops sourcetype="splunk:victorops:incidents:json" "PTS"
| dedup incidentNumber
| eval startTimeFormatted=strptime(startTime,"%Y-%m-%dT%H:%M:%SZ") -18000
| eval SplunkStartTime=strftime(startTimeFormatted,"%m/%d/%y %H:%M:%S")


| eval endTimeFormatted=strptime(lastAlertTime,"%Y-%m-%dT%H:%M:%SZ") -18000
| eval SplunkEndTime=strftime(endTimeFormatted,"%m/%d/%y %H:%M:%S")


| eval MTTR = round((SplunkEndTime-SplunkStartTime)/86400)
| table incidentNumber, SplunkStartTime, routingKey, entityDisplayName, SplunkEndTime, currentPhase, MTTR


Above query  showing "NULL" output to "MTTR" field.

 

Please advise !

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| eval MTTR = tostring(endTimeFormatted-startTimeFormatted,"duration")

View solution in original post

0 Karma

scelikok
SplunkTrust
SplunkTrust

Hi @Manasi25,

Since the time fields are string formatted, MTTR calculation is not possible. Please try below options;

in days;
| eval MTTR =round((lastAlertTime-startTime)/86400)

OR formatted as duration; 
| eval MTTR = tostring(lastAlertTime-startTime, "duration")

 

If this reply helps you an upvote and "Accept as Solution" is appreciated.
0 Karma

Manasi25
Explorer

Hello

Thank you ! 
I used this and this shows "00:00:00" result to all time spam. PFA

Please advise further!

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| eval MTTR = tostring(round((endTimeFormatted-startTimeFormatted)/86400),"duration")
0 Karma

Manasi25
Explorer

Hello @ITWhisperer ,

I searched with your query and still getting "00:00:00" result to all rows.

 

PFA. please help !

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| eval MTTR = tostring(endTimeFormatted-startTimeFormatted,"duration")
0 Karma

Manasi25
Explorer

Hi @ITWhisperer 

This helps and result is good. Thank you !

0 Karma

isoutamo
SplunkTrust
SplunkTrust

Hi

you cannot calculate with string fields. You must use those with numeric values. In your case those are startTimeFormatted and endTimeFormatted.

If you would like to see MTTR as human readable convert it with 

eval MTTR = tostring(MTTR, "duration")

after calculation.

r. Ismo 

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to November Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...

Index This | When is October more than just the tenth month?

October 2025 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Observe and Secure All Apps with Splunk

  Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...