Splunk Search

Why am I getting an Invalid result in span between two dates?

morethanyell
Builder

This code:

   | makeresults
   | eval StartTime = strptime("2018-01-01 00:00:00", "%Y-%m-%d %H:%M:%S")
   | eval EndTime = strptime("2018-01-01 00:10:00", "%Y-%m-%d %H:%M:%S")
   | eval Elapsed = EndTime - StartTime
   | fieldformat Elapsed = strftime(Elapsed, "%H:%M:%S")

results to Elapsed=08:10:00 or eight hours and ten minutes, instead of just ten minutes.

Would like to get some assistance on why this happens and how to fix. Thanks a lot!

0 Karma
1 Solution

HiroshiSatoh
Champion

The function calculates 600 seconds as the epoch time.And time zones are also included.

Epoch Time:600
↓With the time zone added:JST
1970-01-01 09:10:00

Try this!
| fieldformat Elapsed = tostring(Elapsed, "duration")

View solution in original post

HiroshiSatoh
Champion

The function calculates 600 seconds as the epoch time.And time zones are also included.

Epoch Time:600
↓With the time zone added:JST
1970-01-01 09:10:00

Try this!
| fieldformat Elapsed = tostring(Elapsed, "duration")

morethanyell
Builder

Wizardry! | fieldformat Elapsed = tostring(floor(Elapsed), "duration")

Thanks a lot

0 Karma
Get Updates on the Splunk Community!

Platform Newsletter Highlights | March 2023

 March 2023 | Check out the latest and greatestIntroducing Splunk Edge Processor, simplified data ...

Enterprise Security Content Updates (ESCU) - New Releases

In the last month, the Splunk Threat Research Team (STRT) has had 3 releases of new content via the Enterprise ...

Thought Leaders are Validating Your Hard Work and Training Rigor

As a Splunk enthusiast and member of the Splunk Community, you are one of thousands who recognize the value of ...